Table of Contents

ivobuttons Bibliothek

Diese Bibliothek wurde geschrieben, weil die von TigerJython zur Verfügung gestellten Routinen zum Zeichnen und zum Auslesen der Buttons für meinen Geschmack viel zu langsam sind. Die Bibliothek ist sehr minimalistisch, macht keine Überprüfungen (wird z.B. ausserhalb des Bildschirms gezeichnet, kann das Programm z.B. einfach abstürzen).

Interface

Anordnung und Werte der Knöpfe

IVO_L1=1 IVO_R1=8
IVO_L2=2IVO_L3=4 IVO_R3=32IVO_R2=16

Verwendung im TigerJython Simulator

Dazu muss folgende Datei im gleichen Ordner gespeichert werden wie Ihre Programmdatei: ivobuttons.py

Installation auf der OxoCard

Sollte die Bibliothek auf der OxoCard noch nicht installiert sein, kann folgendes Programm auf die OxoCard geladen werden und einmalig ausgeführt werden:

install.py
from oxocard import *
program = "import time\nfrom machine import Pin\nfrom globals import __np\nIVO_L1 = 1\nIVO_L2 = 2\nIVO_L3 = 4\nIVO_R1 = 8\nIVO_R2 = 16\nIVO_R3 = 32\n# L1     R1\n#\n# L2  L3   R3  R2\nclass Ivobuttons:\n def __init__(self):\n  self.pins = [Pin(p, Pin.IN, Pin.PULL_UP if p==0 else Pin.PULL_DOWN) for p in (0, 32, 33, 14, 13, 27)]\n  self.wait = [0 for p in range(6)]\n  self.first = [True for p in range(6)]\n  self.delay = 400\n  self.repeat_delay=0\n def states(self):\n  res=0\n  for i in range(6):\n   ms = time.ticks_ms()\n   if self.pins[i].value()==(0 if i==0 else 1):\n    if self.wait[i]<ms:\n     if self.first[i]:\n      self.wait[i] = ms+self.delay\n      self.first[i] = False\n     else:\n      self.wait[i] = ms+self.repeat_delay\n     res+=1<<i\n   else:\n    self.first[i] = True\n    self.wait[i] = 0\n  return res\nivobuttons = Ivobuttons()\ndef fastDot(x,y,c):\n __np._np[x+y*8]=c\ndef fastGetDot(x,y):\n return __np._np[x+y*8]\ndef fastRepaint():\n __np._np.write()\ndef getms():\n return time.ticks_ms()\n"
with uio.open('ivobuttons.py', 'wb') as f:
    f.write(program)
print("File written!")
display("OK", GREEN)

Beispiele

Demo 24 neue Pixel pro Frame, läuft mit 30 fps

Demo 24 neue Pixel pro Frame, läuft mit 30 fps

ivosdemo.py
from oxocard import *
from ivobuttons import *
 
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
 
clear(BLACK)
 
dirs = ((0,1),(1,0),(0,-1), (-1,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,y,hsv2rgb((h+i/40)%1, 1, (i/24)**1.5))
        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("%d fps" % int(1000/(fps2-fps)))
    fps = fps2

64 neue Pixel pro Bild

64 neue Pixel pro Bild

scrolling.py
from oxocard import *
from ivobuttons import *
 
for n in range(121): 
    for y in range(8):
        for x in range(8):  
            if x > y:
                fastDot((x+n)%8, (y+n)%8, (x*32, y*32,0))  # rgb-Werte von 0 bis 255.
            else:
                fastDot((x+n)%8, (y+n)%8, (0, x*32, y*32))    
    fastRepaint()  # Erst jetzt wird das gezeichnete angezeigt.