MicroPython

From HackerDojo Wiki
Revision as of 19:41, 6 July 2024 by DEFAULT (talk | contribs) (blink'n)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Projects

Red Hot

import random
from machine import Pin
from neopixel import NeoPixel
from time import sleep_ms

p = Pin(12, Pin.OUT)
np = NeoPixel(p, 240)

# Simple as possible
while 1:
 np[random.randrange(0,240)] = (random.randrange(0,10),0,0)
 sleep_ms(10)
 np.write()


Iterations:

>>> def loop(r,s):
...     np[random.randrange(0,240)] = (random.randrange(0,r),0,0)
...     np.write()
...     sleep_ms(s)
... 
>>> r,s=10,10
>>> np.fill((0,0,0))
>>> loop(10,10)
>>> loop(10,10)
>>> np.fill(0,0,0)def loop(
>>> def loop(r,s):
...     while 1:
...         np[random.randrange(0,240)] = (random.randrange(0,r),0,0)
...         np.write()
...         sleep_ms(s)
>>> def loop(r,s):
...     while 1:
...         blink(r)
...         bork()
...         np.write()
...         sleep_ms(s)
... 
>>> def blink(r):
...     np[random.randrange(0,240)] = (random.randrange(0,r),0,0)
... 
>>> def bork():
...     np[random.randrange(0,240)] = (0,0,0)
...     np[random.randrange(0,240)] = (0,0,0)
>>> loop(10,1)
>>> def bork():
...     np[random.randrange(0,240)] = (0,0,0)
...     np[random.randrange(0,240)] = (0,0,0)
...     np[random.randrange(0,240)] = (0,0,0)
...     np[random.randrange(0,240)] = (0,0,0)
...     

https://micropython.org