Skip to content

Commit c22e4d9

Browse files
committed
add simple neopixel example
1 parent f1de093 commit c22e4d9

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ But it's probably easiest to do a Cmd-F/Ctrl-F find on keyword of idea you want.
3636
* [Control Neopixel / WS2812 LEDs](#control-neopixel--ws2812-leds)
3737
* [Control a servo, with animation list](#control-a-servo-with-animation-list)
3838
* [Neopixels / Dotstars](#neopixels--dotstars)
39+
* [Light each LED in order](#light-each-led-in-order)
3940
* [Moving rainbow on built-in board.NEOPIXEL](#moving-rainbow-on-built-in-boardneopixel)
4041
* [Make moving rainbow gradient across LED strip](#make-moving-rainbow-gradient-across-led-strip)
4142
* [Fade all LEDs by amount for chase effects](#fade-all-leds-by-amount-for-chase-effects)
@@ -380,6 +381,30 @@ while True:
380381

381382
## Neopixels / Dotstars
382383

384+
### Light each LED in order
385+
386+
You can access each LED with Python array methods on the `leds` object.
387+
And you can set the LED color with either an RGB tuple (`(255,0,80)`) or an
388+
RGB hex color as a 24-bit number (`0xff0050`)
389+
390+
```py
391+
import time, board, neopixel
392+
393+
led_pin = board.GP5 # which pin the LED strip is on
394+
num_leds = 10
395+
colors = ( (255,0,0), (0,255,0), (0,0,255), 0xffffff, 0x000000 )
396+
397+
leds = neopixel.NeoPixel(led_pin, num_leds, brightness=0.1)
398+
399+
i = 0
400+
while True:
401+
print("led:",i)
402+
for c in colors:
403+
leds[i] = c
404+
time.sleep(0.2)
405+
i = (i+1) % num_leds
406+
```
407+
383408
### Moving rainbow on built-in `board.NEOPIXEL`
384409

385410
In CircuitPython 7, the `rainbowio` module has a `colorwheel()` function.

larger-tricks/bouncy_balls_vectorio.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# bouncy_balls_vectorio.py - use displayio to make simple bouncy balls
22
# 12 Nov 2024 - @todbot / Tod Kurt. Based off bouncy_balls1.py
33
# video demo at https://gist.github.com/todbot/d216cdfd0c13774c713482395429da16
4+
# works on any CircuitPython device with a display, just create a 'display'
45
import time, random
56
import board, busio, displayio, i2cdisplaybus
67
import vectorio
@@ -13,7 +14,7 @@
1314
scl_pin, sda_pin = board.GP15, board.GP14 # pins your display is on
1415
dw,dh = 128,64 # or whatever your display is
1516

16-
# set up the display
17+
# set up the display (change for your setup)
1718
displayio.release_displays()
1819
disp_i2c = busio.I2C(scl=scl_pin, sda=sda_pin, frequency=400_000)
1920
display_bus = i2cdisplaybus.I2CDisplayBus(disp_i2c, device_address=0x3C) # or 0x3D

0 commit comments

Comments
 (0)