from machine import Pin
import time
# -------- Button --------
button = Pin(17, Pin.IN, Pin.PULL_UP)
state = 0 # 0 = FALSE, 1 = TRUE
last_button = 1 # released
print("Ready.")
print("Press & release button to toggle TRUE / FALSE")
while True:
current = button.value()
# detect press -> release
if last_button == 0 and current == 1:
state = 1 - state # toggle
if state == 1:
print("TRUE (1)")
else:
print("FALSE (0)")
last_button = current
time.sleep(0.05) # debounce