Buttons
The StudioBot has two push buttons that can be used to collect user input.
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 delayLast updated