Wheel IDE

Online demo »

PSP, Stick

PSP Stick

This example shows how to use the Mindsensors PSP device to read left and right joysticks.

Code

#project "PSP stick demo"

#include "lib/modules/standard.whl"
#include "lib/modules/device.whl"
#include "lib/modules/sensor.whl"
#include "lib/modules/screen.whl"
#include "lib/modules/psp.whl"

#display "EV3, PSP"

proc drawLeftPosition(number x, number y)
    drawCircle(46 + x / 5, 64 + y / 5, 10)
end

proc drawRightPosition(number x, number y)
    drawCircle(132 + x / 5, 64 + y / 5, 10)
end

proc main()
    ; Select the EV3 device in the simulator...
    selectDevice(DEVICE_EV3)

    pspStart(INPUT_1)

    drawLeftPosition(0, 0)
    drawCircle(46, 64, 40)
    drawRightPosition(0, 0)
    drawCircle(132, 64, 40)
    updateScreen()

    number lastLeftX  = 0
    number lastLeftY  = 0
    number lastRightX = 0
    number lastRightY = 0

    repeat
        number leftX  = pspData.stickLeftX
        number leftY  = pspData.stickLeftY
        number rightX = pspData.stickRightX
        number rightY = pspData.stickRightY

        if leftX != lastLeftX or leftY != lastLeftY
            setFillColor(WHITE)
            drawLeftPosition(lastLeftX, lastLeftY)
            setFillColor(BLACK)
            drawLeftPosition(leftX, leftY)
            updateScreen()
            lastLeftX = leftX
            lastLeftY = leftY
        end
        if rightX != lastRightX or rightY != lastRightY
            setFillColor(WHITE)
            drawRightPosition(lastRightX, lastRightY)
            setFillColor(BLACK)
            drawRightPosition(rightX, rightY)
            updateScreen()
            lastRightX = rightX
            lastRightY = rightY
        end
    end
end
See also: Modules pspStart