This shows you the differences between two versions of the page.
Both sides previous revision
Previous revision
|
|
lehrkraefte:blc:informatik:glf20:ivobuttons [2020/12/07 11:03] Ivo Blöchliger [Beispiele] |
lehrkraefte:blc:informatik:glf20:ivobuttons [2020/12/13 17:05] (current) Ivo Blöchliger [Installation auf der OxoCard] |
<code python install.py> | <code python install.py> |
from oxocard import * | 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*y]\ndef fastRepaint():\n __np._np.write()\ndef getms():\n return time.ticks_ms()\n" | 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: | with uio.open('ivobuttons.py', 'wb') as f: |
f.write(program) | f.write(program) |