-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
neopixel example taken from MicroPython docs
- Loading branch information
1 parent
0cf2301
commit 4e96054
Showing
1 changed file
with
42 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |