from machine import Pin, I2C
from utime import sleep, ticks_ms, ticks_diff
import ssd1306
button1 = Pin(8, Pin.IN, Pin.PULL_UP)
led = Pin(2, Pin.OUT)
last_state = 1
running = False
timer = 10
last_tick = ticks_ms()
while True:
state = button1.value()
if state == 0 and last_state == 1:
led.off()
running = not running
last_tick = ticks_ms()
print(running)
if running == True and ticks_diff(ticks_ms(), last_tick) >= 1000:
last_tick = ticks_ms()
timer -= 1
print(timer)
if timer == 0:
running = False
led.on()
timer = 10
last_state = state
sleep(0.05)
Loading
pi-pico-w
pi-pico-w
Loading
ssd1306
ssd1306