Wheel IDE

Online demo »

Button

This file contains a procedures to read EV3 or Powered Up buttons.

Constants

The button module.
Source: lib/modules/button.whl, line: 9
MODULE_BUTTON4

Module call to read a button.
Source: lib/modules/button.whl, line: 12
BUTTON_READ0
BUTTON_WAIT_FOR_PRESS1

The possible EV3 button values.
Source: lib/modules/button.whl, line: 16
BUTTON_NONE0
BUTTON_UP1
BUTTON_CENTER2
BUTTON_DOWN3
BUTTON_RIGHT4
BUTTON_LEFT5

The Powered Up button bits.
Source: lib/modules/button.whl, line: 24
BUTTON_PU_LEFT_MIN1
BUTTON_PU_LEFT_CENTER2
BUTTON_PU_LEFT_RIGHT4
BUTTON_PU_RIGHT_MIN8
BUTTON_PU_RIGHT_CENTER16
BUTTON_PU_RIGHT_PLUS32

Spike connect button.
Source: lib/modules/button.whl, line: 32
BUTTON_SPIKE_CONNECT6

Procedures

buttonLayer
Source: lib/modules/button.whl, line: 35

Read a button value from a given layer, the layer only applies to Powered Up and Spike devices.

proc buttonLayer(number layer)
Parameters:
NameTypeDescription
layernumberThe layer, the device of which you want to read the buttons.
Return: In case of EV3 then button pressed value -if any-: BUTTON_NONE, BUTTON_LEFT, BUTTON_CENTER, BUTTON_RIGHT, BUTTON_UP or BUTTON_DOWN. In case of Powered Up then the value can contain one or more bits: BUTTON_PU_LEFT_MIN, BUTTON_PU_LEFT_CENTER, BUTTON_PU_LEFT_RIGHT, BUTTON_PU_LEFT_MIN, BUTTON_PU_LEFT_CENTER or BUTTON_PU_LEFT_RIGHT. For Spike the button value can be BUTTON_LEFT, BUTTON_CENTER BUTTON_RIGHT or BUTTON_SPIKE_CONNECT.


button
Source: lib/modules/button.whl, line: 48

Read a button value from a given layer, the layer only applies to Powered Up and Spike devices.

proc button()
Return: In case of EV3 then button pressed value -if any-: BUTTON_NONE, BUTTON_LEFT, BUTTON_CENTER, BUTTON_RIGHT, BUTTON_UP or BUTTON_DOWN. In case of Powered Up then the value can contain one or more bits: BUTTON_PU_LEFT_MIN, BUTTON_PU_LEFT_CENTER, BUTTON_PU_LEFT_RIGHT, BUTTON_PU_LEFT_MIN, BUTTON_PU_LEFT_CENTER or BUTTON_PU_LEFT_RIGHT. For Spike the button value can be BUTTON_LEFT, BUTTON_CENTER BUTTON_RIGHT or BUTTON_SPIKE_CONNECT.

With the button module you can read the state of the EV3 buttons.

#include "lib/modules/button.whl"
#include "lib/modules/screen.whl"

proc main()
    number b
    setTextSize(2)
    repeat
        b = button()
        drawNumber(73, 56, b)
    end
end

waitForPress
Source: lib/modules/button.whl, line: 59

Wait until a button is pressed.

proc waitForPress()