Buttons
The StudioBot has two push buttons that can be used to collect user input.
The following example shows how to setup the robot to use the switches to detect user input. Notice how the values are the opposite to what you would think. i.e. the value True represents off.
import time
import board
from digitalio import DigitalInOut, Direction, Pull
switch1 = DigitalInOut(board.SWITCH1)
switch1.direction = Direction.INPUT
switch2 = DigitalInOut(board.SWITCH2)
switch2.direction = Direction.INPUT
while True:
if switch1.value:
print("Switch 1 Off")
else:
print("Switch 1 On")
if switch2.value:
print("Switch 2 Off")
else:
print("Switch 2 On")
time.sleep(0.01) # debounce delay
Last updated