54 lines
1.1 KiB
Python
54 lines
1.1 KiB
Python
|
import neopixel
|
||
|
from machine import Pin
|
||
|
import time
|
||
|
|
||
|
ws_pin = 0
|
||
|
led_zahl = 64
|
||
|
helligkeit = 0.05
|
||
|
|
||
|
matrix = neopixel.NeoPixel(Pin(ws_pin), led_zahl)
|
||
|
|
||
|
taster_hoch = Pin(1, Pin.IN, Pin.PULL_UP)
|
||
|
taster_runter = Pin(2, Pin.IN, Pin.PULL_UP)
|
||
|
taster_rechts = Pin(3, Pin.IN, Pin.PULL_UP)
|
||
|
taster_links = Pin(4, Pin.IN, Pin.PULL_UP)
|
||
|
|
||
|
def setze_helligkeit(farbe):
|
||
|
r, g, b = farbe
|
||
|
r = int(r * helligkeit)
|
||
|
g = int(g * helligkeit)
|
||
|
b = int(b * helligkeit)
|
||
|
return (r, g, b)
|
||
|
|
||
|
def setze_pixel(x, y, farbe):
|
||
|
farbe = setze_helligkeit(farbe)
|
||
|
i = y * 8 + x
|
||
|
matrix[i] = farbe
|
||
|
|
||
|
x = 0
|
||
|
y = 0
|
||
|
|
||
|
def neue_position(x, y):
|
||
|
if not taster_runter.value():
|
||
|
y = y + 1
|
||
|
if y > 7: y = 7
|
||
|
if not taster_rechts.value():
|
||
|
x = x + 1
|
||
|
if x > 7: x = 7
|
||
|
if not taster_links.value():
|
||
|
x = x - 1
|
||
|
if x < 0: x = 0
|
||
|
if not taster_hoch.value():
|
||
|
y = y - 1
|
||
|
if y < 0: y = 0
|
||
|
return (x, y)
|
||
|
|
||
|
while True:
|
||
|
matrix.fill((0, 0, 0))
|
||
|
|
||
|
(x, y) = neue_position(x, y)
|
||
|
setze_pixel(x, y, (255, 255, 0))
|
||
|
|
||
|
matrix.write()
|
||
|
time.sleep(0.2)
|
||
|
|