Button

The button library allows for detection of button presses from the left and right arrow keys located on the top face of the hub.

Constants

  1. LEFT=0
  2. RIGHT=1

IsLeftPressed()

Returns

boolean
Returns true if left arrow is pressed, false if not

Parameters

None

Example

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!")

IsRightPressed()

Returns

boolean
Returns true if right arrow is pressed, false if not

Parameters

None

Example

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!")

ButtonPressDuration(integer btn)

Returns

integer
Returns duration, the amount of time in milliseconds the provided button has been held down for.

Parameters

  1. 1.integerbtn

    The button to be checked

Example

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")