Tilt Switch
Detects if it has been tilted beyond a certain point.
Basic tilt switch example
# --- Imports
import digitalio
import time
import board
# --- Variables
tilt_switch = digitalio.DigitalInOut(board.GP18)
tilt_switch.direction = digitalio.Direction.INPUT
# --- Functions
# --- Setup
# --- Main loop
while True:
if tilt_switch.value is False:
print("False")
else:
print("True")
time.sleep(0.05) # Make the loop run a little bit slower