Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lehrkraefte:blc:informatik:glf19:oxocard:goodies [2019/11/18 17:16] Ivo Blöchliger |
lehrkraefte:blc:informatik:glf19:oxocard:goodies [2019/11/25 19:25] (current) Ivo Blöchliger [Schnelle Funktionen zur Abfrage der Knöpfe und Pixel zeichnen] |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Schnelle Funktionen zur Abfrage der Knöpfe und Pixel zeichnen ====== | ||
+ | {{ : | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | |||
+ | <hidden Demo 24 neue Pixel pro Frame, läuft mit 40 fps> | ||
+ | <code python ivobuttonsdemo.py> | ||
+ | # | ||
+ | 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, | ||
+ | # 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(" | ||
+ | for k in [250, 100, 50, 20, 10, 5, 1, 0]: | ||
+ | for i in range(8): | ||
+ | __np.set(9*i+1, | ||
+ | __np.set(7*i+8, | ||
+ | __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 * | ||
+ | from ivobuttons import * | ||
+ | |||
+ | def hsv2rgb(h, | ||
+ | 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)), | ||
+ | return rgb | ||
+ | |||
+ | |||
+ | clear(BLACK) | ||
+ | |||
+ | dirs = ((0, | ||
+ | x = 0 | ||
+ | y = 0 | ||
+ | d = 0 | ||
+ | h = 0.0 | ||
+ | |||
+ | a = 0 | ||
+ | b = 0 | ||
+ | dd = 0 | ||
+ | ivobuttons.delay=0 | ||
+ | fps = getms() | ||
+ | while True: | ||
+ | for i in range(24): | ||
+ | fastDot(x, | ||
+ | x+=dirs[d][0] | ||
+ | y+=dirs[d][1] | ||
+ | if (x>7 or x<0 or y>7 or y<0): | ||
+ | x-=dirs[d][0] | ||
+ | y-=dirs[d][1] | ||
+ | d=(d+1)%4 | ||
+ | x+=dirs[d][0] | ||
+ | y+=dirs[d][1] | ||
+ | if (i==0): | ||
+ | a = x | ||
+ | b = y | ||
+ | dd = d | ||
+ | fastRepaint() | ||
+ | s = ivobuttons.states() | ||
+ | if (s & IVO_R2): | ||
+ | sleep(0.05) | ||
+ | if (s & IVO_R3): | ||
+ | sleep(0.15) | ||
+ | h = (h+0.005)%1 | ||
+ | x = a | ||
+ | y = b | ||
+ | d = dd | ||
+ | fps2 = getms() | ||
+ | print(" | ||
+ | fps = fps2 | ||
+ | |||
+ | </ | ||
+ | </ | ||
====== HSV-Farben, Gamma-Faktor ====== | ====== HSV-Farben, Gamma-Faktor ====== | ||
Folgender Code enthält eine Funktion **hsv2rgb**, | Folgender Code enthält eine Funktion **hsv2rgb**, | ||
- | < | + | < |
<code python hsv2rgb.py> | <code python hsv2rgb.py> | ||
# | # |