''' Lampenfeld '''
from machine import Pin
from neopixel import NeoPixel
from time import sleep
z_max = 4 # Ändere 'rows' in 'diagram.json
s_max = 5 # Ändere 'cols' in 'diagram.json
NUM_LEDS = z_max * s_max
pixels = NeoPixel(Pin(2), NUM_LEDS)
oben = Pin( 4, Pin.IN, Pin.PULL_UP) # grün
rechts = Pin(19, Pin.IN, Pin.PULL_UP) # schwarz
links = Pin(21, Pin.IN, Pin.PULL_UP) # grau
OK = Pin(5, Pin.IN, Pin.PULL_UP) # orange
unten = Pin(18, Pin.IN, Pin.PULL_UP) # gelb - Einzelschritt
automatisch = False
an = (255,0,0); an_halb = (128,0,0)
aus = (0,0,64); aus_halb = (0,0,16)
for index in range(NUM_LEDS):
pixels[index] = aus
pixels.write()
def index(z,s):
if z%2==0:
s = s_max - (s-1)
return (z-1)*s_max + (s-1)
def pixel(z,s):
i = index(z,s)
if pixels[i] == an:
pixels[i] = aus
else:
pixels[i] = an
pixels.write()
def pixel_blink(z,s):
i = index(z,s)
last = pixels[i]
pixels[i] = (0,128,0)
pixels.write()
sleep(0.1)
pixels[i] = last
pixels.write()
sleep(0.1)
weiter = True
z = z_max//2
s = s_max//2
while weiter:
print(".", end="")
pixel_blink(z,s)
if oben.value()==0:
z = z-1
if z<1: z=z_max
if unten.value()==0:
z = z+1
if z>z_max: z=1
if links.value()==0:
s = s-1
if s<1: s=s_max
if OK.value()==0:
pixel(z,s)
if z>1: pixel(z-1,s)
if z<z_max: pixel(z+1,s)
if s>1: pixel(z,s-1)
if s<s_max: pixel(z,s+1)
if rechts.value()==0:
s = s+1
if s>s_max: s=1
print("Spiel wurde beendet")