The button library allows for detection of button presses from the left and right arrow keys located on the top face of the hub.
LEFT=0
RIGHT=1
boolean
None
1
2
3
4
5
6
7
8
9
10
11
12
13
use Libraries.Robots.Spike.Button
use Libraries.Robots.Spike.LightMatrix
use Libraries.Robots.Spike.Hub
Hub hb
LightMatrix lights
Button btn
repeat until btn:IsLeftPressed()
hb:Sleep(1)
end
lights:Write("Left Button Pressed!")
boolean
None
1
2
3
4
5
6
7
8
9
10
11
12
13
use Libraries.Robots.Spike.Button
use Libraries.Robots.Spike.LightMatrix
use Libraries.Robots.Spike.Hub
Hub hb
LightMatrix lights
Button btn
repeat until btn:IsRightPressed()
hb:Sleep(1)
end
lights:Write("Right Button Pressed!")
integer
integerbtn
The button to be checked
1
2
3
4
5
6
7
8
9
10
11
12
use Libraries.Robots.Spike.Button
use Libraries.Robots.Spike.LightMatrix
Button btn
LightMatrix lights
integer left_button_duration = 0
repeat until (left_button_duration > 1000)
left_button_duration = btn:ButtonPressDuration(btn:LEFT)
end
lights:Write("Button held for 1 second")