NodeMCU Projects: Difference between revisions
Content added Content deleted
m (Protected "NodeMCU Projects" ([Edit=Allow only logged in users] (indefinite) [Move=Allow only logged in users] (indefinite) [Delete=Allow only logged in users] (indefinite))) |
(→NeoPixel: new version) |
||
Line 66: | Line 66: | ||
import neopixel |
import neopixel |
||
import time |
import time |
||
import urandom |
|||
pin = machine.Pin(14, machine.Pin.OUT) |
pin = machine.Pin(14, machine.Pin.OUT) |
||
np = neopixel.NeoPixel(pin, 16) |
np = neopixel.NeoPixel(pin, 16) |
||
⚫ | |||
return urandom.getrandbits(8) |
|||
def cycle(): |
def cycle(): |
||
for i in range(16): |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
x,y,z = rand(),rand(),rand() |
|||
for i in range(16): |
for i in range(16): |
||
np[i] = ( |
np[i] = (x,y,z) |
||
np.write() |
np.write() |
||
time.sleep_ms(25) |
time.sleep_ms(25) |
||
def circle_rainbow(): |
|||
⚫ | |||
for i in range(16): |
for i in range(16): |
||
np[i] = ( |
np[i] = (rand(),rand(),rand()) |
||
np.write() |
np.write() |
||
time.sleep_ms(25) |
time.sleep_ms(25) |
||
⚫ | |||
⚫ | |||
for i in range(0, 4 * 256, 8): |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
np.write() |
np.write() |
||
⚫ | |||
i += 10 |
|||
⚫ | |||
⚫ | |||
for |
for j in range(16): |
||
if (i // 256) % 2 == 0: |
|||
val = i & 0xff |
|||
else: |
|||
val = 255 - (i & 0xff) |
|||
np[j] = (0, val, 0) |
|||
np.write() |
|||
⚫ | |||
n = np.n |
|||
# cycle |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
# fade in/out |
|||
for i in range(0, 4 * 256, 8): |
for i in range(0, 4 * 256, 8): |
||
for j in range( |
for j in range(16): |
||
if (i // 256) % 2 == 0: |
if (i // 256) % 2 == 0: |
||
val = i & 0xff |
val = i & 0xff |
||
⚫ | |||
val = 255 - (i & 0xff) |
|||
np[j] = (0, 0, val) |
|||
np.write() |
|||
⚫ | |||
for i in range(5): |
|||
x,y,z = rand(),rand(),rand() |
|||
for i in range(4 * 16): |
|||
for j in range(16): |
|||
np[j] = (x,y,z) |
|||
if (i // 16) % 2 == 0: |
|||
np[i % 16] = (0, 0, 0) |
|||
else: |
else: |
||
np[16 - 1 - (i % 16)] = (0, 0, 0) |
|||
np |
np.write() |
||
time.sleep_ms(60) |
|||
# clear |
|||
⚫ | |||
⚫ | |||
⚫ | |||
# Under Construction |
|||
⚫ | |||
pass |
|||
def off(): |
def off(): |
||
Line 140: | Line 151: | ||
np.write() |
np.write() |
||
cycle() |
|||
off() |
|||
time.sleep(1) |
|||
circle() |
|||
off() |
|||
time.sleep(1) |
|||
circle_rainbow() |
|||
off() |
|||
time.sleep(1) |
|||
fade() |
|||
off() |
|||
time.sleep(1) |
|||
bounce() |
|||
off() |
off() |
||
</syntaxhighlight> |
</syntaxhighlight> |