Skip to content

Commit

Permalink
neopixel example taken from MicroPython docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomas-fryza committed Nov 27, 2024
1 parent 0cf2301 commit 4e96054
Showing 1 changed file with 42 additions and 7 deletions.
49 changes: 42 additions & 7 deletions examples/20-neopixel/main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,49 @@
# https://docs.micropython.org/en/latest/esp8266/tutorial/neopixel.html

from machine import Pin
from neopixel import NeoPixel
import time

n_leds = 60
data_pin = 25
def demo(np):
n_leds = np.n
print(f"{n_leds} LEDs")

print("cycle")
for i in range(1 * n_leds):
for j in range(n_leds):
np[j] = (0, 0, 0)
np[i % n_leds] = (255, 255, 255)
np.write()
time.sleep_ms(125)

np = NeoPixel(Pin(data_pin), n_leds)
print("bounce")
for i in range(1 * n_leds):
for j in range(n_leds):
np[j] = (0, 0, 128)
if (i // n_leds) % 2 == 0:
np[i % n_leds] = (0, 0, 0)
else:
np[n_leds - 1 - (i % n_leds)] = (0, 0, 0)
np.write()
time.sleep_ms(60)

for i in range(n_leds):
np[i] = (255, 0, 0)
print("fade in/out")
for i in range(0, 4 * 256, 8):
for j in range(n_leds):
if (i // 256) % 2 == 0:
val = i & 0xff
else:
val = 255 - (i & 0xff)
np[j] = (val, 0, 0)
np.write()

print("clear")
for i in range(n_leds):
np[i] = (0, 0, 0)
np.write()
print(f"LED #{i}")
time.sleep_ms(250)

# Vcc
# GND
# 15/A4 (FireBeetle v2)
np = NeoPixel(Pin(15), 60) # 60 LEDs
demo(np)

0 comments on commit 4e96054

Please sign in to comment.