MicroPython: Difference between revisions

From HackerDojo Wiki
Jump to navigation Jump to search
(blink'n)
 
m (eternal flame)
Line 2: Line 2:


=== Red Hot ===
=== Red Hot ===
main.py


<pre>
<pre>
Line 9: Line 11:
from time import sleep_ms
from time import sleep_ms


p = Pin(12, Pin.OUT)
r,s=10,10
np = NeoPixel(p, 240)
 
p=Pin(12,Pin.OUT)
np=NeoPixel(p,240)
 
def simple():
# Simple as possible
while 1:
  np[random.randrange(0,240)]=(random.randrange(0,10),0,0)
  sleep_ms(10)
  np.write()


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


</pre>
def loop(r,s):
np.fill((0,2,8))
while 1:
  #Upper red sparks
  blink(r)
  bork()
  #Base burning
  base(10,30,0,12)
  np.write()
  sleep_ms(s)
 
def base(redMin,redMax,grnMin,grnMax):
for i in range(53,150):
  np[i]=(random.randrange(redMin,redMax),random.randrange(grnMin,grnMax),0)


def blink(r):
np[random.randrange(150,240)]=(random.randrange(0,r),0,0)


Iterations:
def bork():
np[random.randrange(180,240)]=(0,0,0)
np[random.randrange(210,240)]=(0,0,0)
np[random.randrange(220,240)]=(0,0,0)
np[random.randrange(220,240)]=(0,0,0)


<pre>
print("Blinker for WS2812b RGBx240 strip")
>>> def loop(r,s):
print("loop(r,s) #Intensity[2-256],Delay(ms)")
...    np[random.randrange(0,240)] = (random.randrange(0,r),0,0)
print("simple() #Alternative random one-liner")
...    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)
...   


loop(66,10)
</pre>
</pre>


https://micropython.org
https://micropython.org

Revision as of 20:34, 6 July 2024

Projects

Red Hot

main.py

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

r,s=10,10

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

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

#simple()

def loop(r,s):
 np.fill((0,2,8))
 while 1:
  #Upper red sparks
  blink(r)
  bork()
  #Base burning
  base(10,30,0,12)
  np.write()
  sleep_ms(s)

def base(redMin,redMax,grnMin,grnMax):
 for i in range(53,150):
  np[i]=(random.randrange(redMin,redMax),random.randrange(grnMin,grnMax),0)

def blink(r):
 np[random.randrange(150,240)]=(random.randrange(0,r),0,0)

def bork():
 np[random.randrange(180,240)]=(0,0,0)
 np[random.randrange(210,240)]=(0,0,0)
 np[random.randrange(220,240)]=(0,0,0)
 np[random.randrange(220,240)]=(0,0,0)

print("Blinker for WS2812b RGBx240 strip")
print("loop(r,s) #Intensity[2-256],Delay(ms)")
print("simple() #Alternative random one-liner")

loop(66,10)


https://micropython.org