import time
import board
import defs
from neopixel import NeoPixel as _NeoPixel
from switch import Switch as _Switch
# Blau von links nach rechts
sw1 = _Switch(board.GP1, 1)
sw2 = _Switch(board.GP28, 2) #.GP25)
sw3 = _Switch(board.GP27, 3) #.GP24)
sw4 = _Switch(board.GP26, 4) #.GP23)
# Gelb von links nach rechts
swA = _Switch(board.GP9, 5)
swB = _Switch(board.GP10, 6)
swC = _Switch(board.GP11, 7)
swD = _Switch(board.GP12, 8) #.GP18)
# Grün von oben nach unten
swUp = _Switch(board.GP20, 9)
swDown = _Switch(board.GP19, 10)
LED_PIN = board.GP7
pixel = _NeoPixel(LED_PIN, 3, brightness=0.5, auto_write=False)
pixel[0] = (255, 0, 0)
pixel[1] = (0, 255, 0)
pixel[2] = (0, 0, 255)
pixel.show()
while True:
# Aktuell ist kein Button gedrückt
if sw1.sw.value and sw2.sw.value and sw3.sw.value and sw4.sw.value and \
swA.sw.value and swB.sw.value and swC.sw.value and swD.sw.value and \
swUp.sw.value and swDown.sw.value:
# Es war aber vorher ein Button gedrückt, d.h., er wurde gerade losgelassen
ret = sw1.Release() + sw2.Release() + sw3.Release() + sw4.Release() + \
swA.Release() + swB.Release() + swC.Release() + swD.Release() + \
swUp.Release() + swDown.Release()
if ret == 1:
print("Switch 1 Release")
elif ret == 2:
print("Switch 2 Release")
elif ret == 3:
print("Switch 3 Release")
elif ret == 4:
print("Switch 4 Release")
elif ret == 5:
print("Switch A Release")
elif ret == 6:
print("Switch B Release")
elif ret == 7:
print("Switch C Release")
elif ret == 8:
print("Switch D Release")
elif ret == 9:
print("Switch Up Release")
elif ret == 10:
print("Switch Down Release")
elif ret == 101:
print("Switch 1 Release")
print("Switch 1 Long Release")
elif ret == 102:
print("Switch 2 Release")
print("Switch 2 Long Release")
elif ret == 103:
print("Switch 3 Release")
print("Switch 3 Long Release")
elif ret == 104:
print("Switch 4 Release")
print("Switch 4 Long Release")
elif ret == 105:
print("Switch A Release")
print("Switch A Long Release")
elif ret == 106:
print("Switch B Release")
print("Switch B Long Release")
elif ret == 107:
print("Switch C Release")
print("Switch C Long Release")
elif ret == 108:
print("Switch D Release")
print("Switch D Long Release")
elif ret == 109:
print("Switch Up Release")
print("Switch Up Long Release")
elif ret == 110:
print("Switch Down Release")
print("Switch Down Long Release")
# Mindestens ein Button ist aktuell gedrückt
else:
ret1 = sw1.Press()
ret2 = sw2.Press()
ret3 = sw3.Press()
ret4 = sw4.Press()
ret5 = swA.Press()
ret6 = swB.Press()
ret7 = swC.Press()
ret8 = swD.Press()
ret9 = swUp.Press()
ret10 = swDown.Press()
# Button wird zum ersten Mal gedrückt
if ret1 == 1:
print("Switch 1 Press")
elif ret2 == 2:
print("Switch 2 Press")
elif ret3 == 3:
print("Switch 3 Press")
elif ret4 == 4:
print("Switch 4 Press")
elif ret5 == 5:
print("Switch A Press")
elif ret6 == 6:
print("Switch B Press")
elif ret7 == 7:
print("Switch C Press")
elif ret8 == 8:
print("Switch D Press")
elif ret9 == 9:
print("Switch Up Press")
elif ret10 == 10:
print("Switch Down Press")
elif ret1 == 101:
print("Switch 1 Long Press")
elif ret2 == 102:
print("Switch 2 Long Press")
elif ret3 == 103:
print("Switch 3 Long Press")
elif ret4 == 104:
print("Switch 4 Long Press")
elif ret5 == 105:
print("Switch A Long Press")
elif ret6 == 106:
print("Switch B Long Press")
elif ret7 == 107:
print("Switch C Long Press")
elif ret8 == 108:
print("Switch D Long Press")
elif ret9 == 109:
print("Switch Up Long Press")
elif ret10 == 110:
print("Switch Down Long Press")
time.sleep(0.02) # debounce delay