MicroPython: Difference between revisions

From HackerDojo Wiki
Jump to navigation Jump to search
(blink'n)
 
m (pics)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
== Projects ==
== Projects ==
[[File:ESP32.jpg|800px]]


=== Red Hot ===
=== Red Hot ===
[[File:NeoPixel_WS2812b.jpg|800px]]
main.py


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


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


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


</pre>
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)


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

Latest revision as of 21:32, 6 July 2024

Projects

ESP32.jpg

Red Hot

NeoPixel WS2812b.jpg

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