# https://wokwi.com/projects/469730316438830081
# https://wokwi.com/projects/469724724687572993
# https://docs.wokwi.com/parts/wokwi-led-matrix
# fehlerhaft:
# https://wokwi.com/projects/469641338662642689
# wokwi version of Trinkets
# Trinket plus Raspi equals love
#
from machine import Pin
import time
time.sleep(0.1) # Wait for USB to become ready
# ------------------------------
# GPIO-Belegung
# ------------------------------
print("Start 1")
button_pins = [11, 12, 13, 14, 15]
led_pins = [16, 17, 18, 19, 20]
"""
# LEDs erzeugen
leds = [Pin(pin, Pin.OUT) for pin in led_pins]
# Status der LEDs
led_state = [0, 0, 0, 0, 0]
# Entprellung
last_press = [0, 0, 0, 0, 0]
DEBOUNCE_MS = 50
# ------------------------------
# Interrupt-Funktion
# ------------------------------
def make_callback(index):
def callback(pin):
now = time.ticks_ms()
if time.ticks_diff(now, last_press[index]) > DEBOUNCE_MS:
last_press[index] = now
led_state[index] ^= 1
leds[index].value(led_state[index])
#print("Taster", index + 1,
# "LED =", led_state[index])
return callback
# ------------------------------
# Taster konfigurieren
# ------------------------------
buttons = []
for i, pin in enumerate(button_pins):
btn = Pin(pin, Pin.IN, Pin.PULL_UP)
btn.irq(
trigger=Pin.IRQ_FALLING,
handler=make_callback(i)
)
buttons.append(btn)
#print("ESP32 gestartet")
#print("Warte auf Tastendruck...")
# ------------------------------
# Hauptschleife
# ------------------------------
"""
while True:
print("RPi läuft. ")
time.sleep(1)