#Initialisierung der Oxocard try: from machine import Pin, deepsleep, ADC, reset from globals import __np import time Pin(2, Pin.OUT).value(1) # audio ampli on Pin(15, Pin.OUT).value(0) # neopix on __np.set(37, 0xffff00, update = True) # Möglichkeit zum Ausschalten... for i in range(50): if Pin(13, Pin.IN, Pin.PULL_DOWN).value() == 1 and Pin(27, Pin.IN, Pin.PULL_DOWN).value() == 1: print("Power off") for k in [250, 100, 50, 20, 10, 5, 1, 0]: for i in range(8): __np.set(9*i+1, k << 16, update = False) __np.set(7*i+8, k << 16, update = False) __np.show() time.sleep(0.5) Pin(2, Pin.OUT).value(0) # audio ampli off Pin(15, Pin.OUT).value(1) # neopix off deepsleep() time.sleep(0.02) except ImportError: pass ################################### # Start vom eigentlichen Programm # ################################### from oxocard import * # Farbe von Hue (Farbton, von 0 bis 1.0), Saturation (Sättigung, von 0 bis 1) und Value (Helligkeit, von 0 bis 1) # Formel von von https://www.rapidtables.com/convert/color/hsv-to-rgb.html def hsv2rgb(h,s,v): c = v*s x = c*(1-abs(h*6 % 2 -1)) m = c-v rgb = (0,0,0) if (h<1/6): rgb = (c,x,0) elif h<2/6: rgb = (x,c,0) elif h<3/6: rgb = (0,c,x) elif h<4/6: rgb = (0,x,c) elif h<5/6: rgb = (x,0,c) else: rgb = (c,0,x) rgb = ((int((rgb[0]+m)*255)), (int((rgb[1]+m)*255)),(int((rgb[2]+m)*255))) return rgb # Wendet einen Gamma-Faktor (default 2) auf einen RGB-Wert an. def gamma(rgb, gamma=2): return (int((rgb[0]/255)**gamma*255), int((rgb[1]/255)**gamma*255),int((rgb[2]/255)**gamma*255)) def regenbogen(offset=0): for y in range(8): for x in range(8): # Nummer des Pixels, von 0 bis 63 nr = (x+8*y+offset)%64 # Hue (Farbton ist nr/64) rgb = hsv2rgb(nr/64,1,1) dot(x,y,gamma(rgb)) enableRepaint(False) while True: for i in range(64): regenbogen(i) repaint()