This example shows how to read the EV3 buttons. The program has a main loop in which the buttons are read. If the button value is different from the last value then a switch statement is used to check which button is pressed.
; Wheel, copyright (c) 2017 - present by Arno van der Vegt ; Distributed under an MIT license: https://arnovandervegt.github.io/wheel/license.txt "EV3 Button example" "lib/modules/standard.whl" "lib/modules/device.whl" "lib/modules/screen.whl" "lib/modules/button.whl" "EV3" proc drawUp() drawRect(71, 21, 38, 18) end proc drawDown() drawRect(71, 89, 38, 18) end proc drawCenter() drawRect(71, 45, 38, 38) end proc drawLeft() drawRect(47, 45, 18, 38) end proc drawRight() drawRect(115, 45, 18, 38) end proc drawScreen() setFill(FALSE) setFillColor(BLACK) ; Up drawRect(70, 20, 40, 20) ; Down drawRect(70, 88, 40, 20) ; Center drawRect(70, 44, 40, 40) ; Left drawRect(46, 44, 20, 40) ; Right drawRect(114, 44, 20, 40) updateScreen() end proc main() selectDevice(DEVICE_EV3) drawScreen() setFill(TRUE) number lastButton = 0 repeat number b = button() ; Read the EV3 button... if lastButton != b number left = WHITE number right = WHITE number center = WHITE number up = WHITE number down = WHITE select b case BUTTON_LEFT: left = BLACK case BUTTON_RIGHT: right = BLACK case BUTTON_CENTER: center = BLACK case BUTTON_UP: up = BLACK case BUTTON_DOWN: down = BLACK end lastButton = b setFillColor(up) drawUp() setFillColor(down) drawDown() setFillColor(center) drawCenter() setFillColor(left) drawLeft() setFillColor(right) drawRight() updateScreen() end end end