"""
RGB-LED-Würfel mit 8x8-Neopixel-Matrix - Vorgabe
QuadPixel
"""
from machine import Pin
from neopixel import NeoPixel
from time import sleep
from random import randrange
NUM_LEDS = 64*6
pixels = NeoPixel(Pin(2), NUM_LEDS)
for i in range(NUM_LEDS):
red = randrange(0,64)
green = randrange(0,64)
blue = randrange(0,64)
pixels[i]=(red, green, blue)
#pixels.write()
#sleep(0.01)
pixels.write()
r = (255, 0, 0); b = (0, 0, 255); g = (0, 255, 0); y = (255,255,0)
def pixel(z,s,f):
s1 = s // 8
s2 = s % 8
z1 = z // 8
z2 = z % 8
if z2 == 0:
z2 = 8
z1 = z1-1
if s2==0:
s2 = 8
s1 = s1-1
if z%2 == 0: # z = 2 4 6 8 10 12 ..
index = z2 * 8 - s2 + s1*64 + z1*3*64
else: # z = 1 3 5 7 9 11 ...
index = (z2-1) * 8 + s2 - 1 + s1*64 + z1*3*64
print(z,s, s1,s2, z1,z2, index)
if index<NUM_LEDS:
pixels[index] = f
pixel(1,1,r); pixel(1,8,b); pixel(8,1,g); pixel(8,8,y)
pixel(1,9,r); pixel(1,16,b); pixel(8,9,g); pixel(8,16,y)
pixel(1,17,r); pixel(1,24,b); pixel(8,17,g); pixel(8,24,y)
pixel(9,1,r); pixel(9,8,b); pixel(16,1,g); pixel(16,8,y)
pixel(9,9,r); pixel(9,16,b); pixel(16,9,g); pixel(16,16,y)
pixel(9,17,r); pixel(9,24,b); pixel(16,17,g); pixel(16,24,y)
#pixels[3*64+0] = (0,128,128)
pixels.write()