The Circuit Playground can be used for more than just outputting information (like you've done with LED), it can also be used as an input device. The simplest forms of input available on the board are the buttons and the switch.
The Reset Button isn't actually available for you to use in your program. Clicking this button causes the board to reset itself, so avoid clicking it while running a program. It is useful, however, if your board isn't functioning the way you expect.
The left and right buttons are available in code as buttonL
and buttonR
respectively. These buttons are identical to each other aside from location on the board.
Note that the left and right assume that you are looking at the board with the USB port at the top.
The Toggle Switch is available in code as toggleSwitch
.
Event Type | Description |
---|---|
down |
Triggers when the button is pressed down. |
up |
Triggers when the button pops back up after being pressed. |
Event Type | Description |
---|---|
open |
When the toggleSwitch is flipped to open (or true ) |
close |
When the toggleSwitch is flipped to closed (or false ) |
change |
When the toggleSwitch is flipped at all |
The buttons and switch are similar in that they are both binary inputs - they can only be in one of two states.
The buttons are normally off, or false
, and change to on, or true
, when you push them down. You can check whether a button is being pressed using the boolean buttonL.isPressed
.
The switch, however, stays in whichever position you last put it in. When the switch is on the left it’s open, or true
, and on the right it’s closed, or false
.
The switch has little plus and minus signs printed on either side of it to help you remember. You can check which state the switch is in with the toggleSwitch.isOpen
boolean.
Found a bug in the documentation? Let us know at documentation@code.org