STEMBoT 2 User’s Manual
========================================================================
The three available colors, red, green, and blue, are numbered 1, 2, and 3, respectively,
when using the LED() function.
4.2.2.0 Switches
As detailed in the Hardware Overview (section 2.1.0.0 of this guide) the SB2 has five
programmable switches. These buttons can be used by importing the machine Python module.
The switches by default are configured as inputs with their pull-up resistors enabled, as the
following code demonstrates.
pinS8=machine.Pin('E5',machine.Pin.IN,machine.Pin.PULL_UP)
pinS7=machine.Pin('B6',machine.Pin.IN,machine.Pin.PULL_UP)
pinS6=machine.Pin('B5',machine.Pin.IN,machine.Pin.PULL_UP)
pinS5=machine.Pin('B2',machine.Pin.IN,machine.Pin.PULL_UP)
pinS4=machine.Pin('F11',machine.Pin.IN,machine.Pin.PULL_UP)
The pins above are named for their label on the PCB. Their values can be read with the
value() method of the Switch() class in the switch module.
Caution: The Pin() function of the machine module can also be used to access other
pins on the SB2’s main microcontroller. Changing the function or value of certain pins
may render critical functions of the SB2 inoperable.
As an example of how the switches work, open a serial connection to the SB2. Type in
the following lines, pressing enter after each one.
from switch import Switch
button=Switch(“up”)
button.value()
Program 3: Getting the State of the Up Button
After entering the last line, False should appear on the serial terminal. This indicates that
the button is not being pressed. Now, hold down the upper left button and send the
button.value() line again. The 0 that appears on the serial terminal indicates the button is
being pressed. Sampling this value is how the buttons are used to scroll through the main
menu, but they can also be used for custom programs.
Note: In the serial terminal, the last line of code can be quickly accessed by pressing the
up button on your keyboard.
========================================================================
Revision 1.1.0 : January 2021