Wheel IDE

Online demo »

Remote control

Powered Up Remote control example

This example shows how to read the Powered Up remote buttons.

This example expects the remote to be connected as the first layer INPUT_1.

Code

#project "Powered Up Remote control example"

#include "lib/modules/standard.whl"
#include "lib/modules/sensor.whl"
#include "lib/modules/device.whl"
#include "lib/modules/bit.whl"
#include "lib/modules/button.whl"

#display "Hub"

proc printButton(number button)
    clearConsole()
    if bitAnd(button, BUTTON_PU_LEFT_MIN) == BUTTON_PU_LEFT_MIN
        printS("Left min button")
    end
    if bitAnd(button, BUTTON_PU_LEFT_CENTER) == BUTTON_PU_LEFT_CENTER
        printS("Left center button")
    end
    if bitAnd(button, BUTTON_PU_LEFT_RIGHT) == BUTTON_PU_LEFT_RIGHT
        printS("Left plus button")
    end
    if bitAnd(button, BUTTON_PU_RIGHT_MIN) == BUTTON_PU_RIGHT_MIN
        printS("Right min button")
    end
    if bitAnd(button, BUTTON_PU_RIGHT_CENTER) == BUTTON_PU_RIGHT_CENTER
        printS("Right center button")
    end
    if bitAnd(button, BUTTON_PU_RIGHT_PLUS) == BUTTON_PU_RIGHT_PLUS
        printS("Right plus button")
    end
end

proc main()
    ; Select the Powered Up device in the IDE...
    selectDevice(DEVICE_POWERED_UP)

    number lastButton = 0
    repeat
        number b = buttonLayer(INPUT_1)

        ; Check if the button value is changed:
        if b != lastButton
            lastButton = b
            printButton(lastButton)
        end
    end
end
See also: Modules button