Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
lehrkraefte:blc:informatik:glf19:oxocard:goodies [2019/11/05 14:26] Ivo Blöchliger created |
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 ====== | ||
+ | Folgender Code enthält eine Funktion **hsv2rgb**, | ||
+ | <hidden Programm mit Konverter-Funktionen> | ||
+ | <code python hsv2rgb.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 * | ||
+ | |||
+ | # Farbe von Hue (Farbton, von 0 bis 1.0), Saturation (Sättigung, | ||
+ | # Formel von von https:// | ||
+ | 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 | ||
+ | |||
+ | # Wendet einen Gamma-Faktor (default 2) auf einen RGB-Wert an. | ||
+ | def gamma(rgb, gamma=2): | ||
+ | return (int((rgb[0]/ | ||
+ | |||
+ | |||
+ | 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/ | ||
+ | dot(x, | ||
+ | | ||
+ | | ||
+ | enableRepaint(False) | ||
+ | while True: | ||
+ | for i in range(64): | ||
+ | regenbogen(i) | ||
+ | repaint() | ||
+ | | ||
+ | </ | ||
+ | </ | ||
+ | ====== Bild-Konverter ====== | ||
+ | Das folgende TigerJython Programm transformiert ein | ||
+ | beliebiges Bild in eine matrix, die mit image(matrix) auf der OxoCard ausgegeben werden kann. | ||
+ | |||
+ | {{ : | ||
+ | |||
+ | Verwendung: | ||
+ | <hidden Verwendung> | ||
+ | <code python imgtest.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 * | ||
+ | |||
+ | while True: | ||
+ | # Art 0, gamma 2 | ||
+ | matrix=(((12, | ||
+ | image(matrix) | ||
+ | sleep(1) | ||
+ | # Art 0, gamma 1.4 | ||
+ | matrix=(((30, | ||
+ | image(matrix) | ||
+ | sleep(1) | ||
+ | # Art 1, gamma 2 | ||
+ | matrix=(((12, | ||
+ | image(matrix) | ||
+ | sleep(1) | ||
+ | | ||
+ | </ | ||
+ | </ | ||
+ | |||
====== Labyrinth ====== | ====== Labyrinth ====== | ||
Anleitung: | Anleitung: |