-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
752 additions
and
283 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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# SPDX-FileCopyrightText: 2024 Mike Causer <https://github.com/mcauser> | ||
# SPDX-License-Identifier: MIT | ||
|
||
""" | ||
MicroPython P9813 RGB LED driver | ||
https://github.com/mcauser/micropython-p9813 | ||
""" | ||
|
||
from machine import Pin | ||
import p9813 | ||
|
||
# TinyPICO (esp32) | ||
clk = Pin(4, Pin.OUT) | ||
data = Pin(14, Pin.OUT) | ||
|
||
# Bit-banged, 10 LEDs, auto-write on | ||
num_leds = 10 | ||
chain = p9813.P9813_BITBANG(clk, data, num_leds, True) | ||
|
||
# With auto-write enabled, each time you modify the LEDs, it calls | ||
# write() and sends the data for every pixel in the chain. | ||
|
||
# You can't update a single LED. You have to write the data for all. | ||
|
||
# When making lots of individual LED changes, it's faster to defer | ||
# writing until all changes have been made. | ||
|
||
# Set first LED to red | ||
chain[0] = (127, 0, 0) | ||
# Notice it's immediately red | ||
|
||
# Switch off auto-write | ||
chain.auto_write = False | ||
|
||
# Set second LED to green | ||
chain[1] = (0, 127, 0) | ||
|
||
# Set third LED to blue | ||
chain[2] = (0, 0, 127) | ||
|
||
# With auto-write off, modifications to the chain only update | ||
# the internal buffer (checksum + red + green + blue values) | ||
# Calling write() later sends the buffer to all LEDs. | ||
|
||
# Notice the second and third LEDs are not lit yet | ||
chain.write() | ||
# Now they are lit | ||
|
||
# Switch auto-write back on | ||
chain.auto_write = True | ||
|
||
# Make all LEDs green | ||
chain.fill((0, 127, 0)) | ||
# Auto-write is temporarily ignored as fill() populates the entire buffer. | ||
# Once the buffer is ready, if auto-write was previously on, data is send out. |
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,27 +1,46 @@ | ||
# SPDX-FileCopyrightText: 2017 Mike Causer <https://github.com/mcauser> | ||
# SPDX-License-Identifier: MIT | ||
|
||
""" | ||
MicroPython P9813 RGB LED driver | ||
https://github.com/mcauser/micropython-p9813 | ||
""" | ||
|
||
from machine import Pin | ||
import p9813 | ||
|
||
pin_clk = Pin(5, Pin.OUT) | ||
pin_data = Pin(4, Pin.OUT) | ||
# TinyPICO (esp32) | ||
clk = Pin(4, Pin.OUT) | ||
data = Pin(14, Pin.OUT) | ||
|
||
# TinyS2 (esp32s2) | ||
# clk = Pin(4, Pin.OUT) | ||
# data = Pin(5, Pin.OUT) | ||
|
||
# Wemos D1 Mini (esp8266) | ||
# clk = Pin(4, Pin.OUT) | ||
# data = Pin(5, Pin.OUT) | ||
|
||
# Bit-banged, 10 LEDs, auto-write off | ||
num_leds = 10 | ||
chain = p9813.P9813(pin_clk, pin_data, num_leds) | ||
auto_write = False | ||
chain = p9813.P9813_BITBANG(clk, data, num_leds, auto_write) | ||
|
||
# set the first pixel to red | ||
# Set the first LED to red | ||
chain[0] = (255, 0, 0) | ||
|
||
# set the first pixel to green | ||
# Set the second LED to green | ||
chain[1] = (0, 255, 0) | ||
|
||
# set the first pixel to blue | ||
# Set the third LED to blue | ||
chain[2] = (0, 0, 255) | ||
|
||
# changes are not visible until you... | ||
# write data to all pixels | ||
# With auto-write off, changes are not seen until you call write() | ||
chain.write() | ||
|
||
# get first pixel colour | ||
r, g, b = chain[0] | ||
# Get second LED colour | ||
(r, g, b) = chain[2] | ||
|
||
# get second pixel colour | ||
r, g, b = chain[1] | ||
# Print as hex colour | ||
print(f"{r:02X}{g:02X}{b:02X}") | ||
# prints 00FF00 |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# SPDX-FileCopyrightText: 2024 Mike Causer <https://github.com/mcauser> | ||
# SPDX-License-Identifier: MIT | ||
|
||
""" | ||
MicroPython P9813 RGB LED driver | ||
https://github.com/mcauser/micropython-p9813 | ||
""" | ||
|
||
from machine import Pin | ||
import p9813 | ||
|
||
# TinyPICO (esp32) | ||
clk = Pin(4, Pin.OUT) | ||
data = Pin(14, Pin.OUT) | ||
|
||
# Bit-banged, 10 LEDs, auto-write on | ||
num_leds = 10 | ||
chain = p9813.P9813_BITBANG(clk, data, num_leds, True) | ||
|
||
|
||
def refresh_rate_test(count): | ||
red = (16, 0, 0) | ||
green = (0, 16, 0) | ||
blue = (0, 0, 16) | ||
colors = [red, green, blue] | ||
for i in range(count): | ||
chain[i % num_leds] = colors[i % 3] | ||
|
||
|
||
# For ~4 seconds, rapidly draw red, green, blue incrementally. | ||
# Roughly 2x slower than Software SPI at baud 100_000. | ||
# Running the same test will instead of showing solid white LEDs, | ||
# show them all flickering as it rapidly draws the colours. | ||
refresh_rate_test(500) |
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,25 +1,41 @@ | ||
# SPDX-FileCopyrightText: 2017 Mike Causer <https://github.com/mcauser> | ||
# SPDX-License-Identifier: MIT | ||
|
||
""" | ||
MicroPython P9813 RGB LED driver | ||
https://github.com/mcauser/micropython-p9813 | ||
""" | ||
|
||
from machine import Pin | ||
import p9813 | ||
from time import sleep_ms | ||
import p9813 | ||
|
||
# TinyPICO (esp32) | ||
clk = Pin(4, Pin.OUT) | ||
data = Pin(14, Pin.OUT) | ||
|
||
# Bit-banged, 10 LEDs, auto-write off | ||
num_leds = 10 | ||
chain = p9813.P9813(Pin(5), Pin(4), num_leds) | ||
chain = p9813.P9813_BITBANG(clk, data, num_leds, False) | ||
|
||
|
||
def bounce(color, sleep): | ||
for i in range(4 * num_leds): | ||
for j in range(num_leds): | ||
chain[j] = color | ||
if (i // num_leds) % 2 == 0: | ||
chain[i % num_leds] = (0, 0, 0) | ||
else: | ||
chain[num_leds - 1 - (i % num_leds)] = (0, 0, 0) | ||
chain.write() | ||
sleep_ms(sleep) | ||
|
||
red = (16,0,0) | ||
green = (0,16,0) | ||
colors = [red,green] | ||
|
||
# Bounce a dark pixel back and forth | ||
for i in range(4 * num_leds): | ||
for j in range(num_leds): | ||
chain[j] = color | ||
if (i // num_leds) % 2 == 0: | ||
chain[i % num_leds] = (0, 0, 0) | ||
else: | ||
chain[num_leds - 1 - (i % num_leds)] = (0, 0, 0) | ||
chain.write() | ||
sleep_ms(sleep) | ||
|
||
|
||
# Test colours | ||
red = (16, 0, 0) | ||
green = (0, 16, 0) | ||
colors = [red, green] | ||
|
||
# Bounce a dark (off) LED back and forth | ||
for color in colors: | ||
bounce(color, 0) | ||
bounce(color, 0) |
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
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,29 +1,44 @@ | ||
# SPDX-FileCopyrightText: 2017 Mike Causer <https://github.com/mcauser> | ||
# SPDX-License-Identifier: MIT | ||
|
||
""" | ||
MicroPython P9813 RGB LED driver | ||
https://github.com/mcauser/micropython-p9813 | ||
""" | ||
|
||
from machine import Pin | ||
import p9813 | ||
from time import sleep_ms | ||
import p9813 | ||
|
||
# TinyPICO (esp32) | ||
clk = Pin(4, Pin.OUT) | ||
data = Pin(14, Pin.OUT) | ||
|
||
# Bit-banged, 10 LEDs, auto-write off | ||
num_leds = 10 | ||
chain = p9813.P9813(Pin(5), Pin(4), num_leds) | ||
chain = p9813.P9813_BITBANG(clk, data, num_leds, False) | ||
|
||
|
||
def cycle(color, sleep): | ||
for i in range(num_leds): | ||
for j in range(num_leds): | ||
chain[j] = (0, 0, 0) | ||
chain[i % num_leds] = color | ||
chain.write() | ||
sleep_ms(sleep) | ||
|
||
# Predefine some colours | ||
red = (16,0,0) | ||
green = (0,16,0) | ||
blue = (0,0,16) | ||
cyan = (0,16,16) | ||
magenta = (16,0,16) | ||
yellow = (16,16,0) | ||
white = (16,16,16) | ||
black = (0,0,0) | ||
colors = [red,green,blue,cyan,magenta,yellow,white,black] | ||
|
||
# Illuminate the pixels one by one | ||
for i in range(num_leds): | ||
for j in range(num_leds): | ||
chain[j] = (0, 0, 0) | ||
chain[i % num_leds] = color | ||
chain.write() | ||
sleep_ms(sleep) | ||
|
||
|
||
# Test colours | ||
red = (16, 0, 0) | ||
green = (0, 16, 0) | ||
blue = (0, 0, 16) | ||
cyan = (0, 16, 16) | ||
magenta = (16, 0, 16) | ||
yellow = (16, 16, 0) | ||
white = (16, 16, 16) | ||
black = (0, 0, 0) | ||
colors = [red, green, blue, cyan, magenta, yellow, white, black] | ||
|
||
# Illuminate the LEDs one-by-one | ||
for color in colors: | ||
cycle(color, 0) | ||
cycle(color, 10) |
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,18 +1,33 @@ | ||
# SPDX-FileCopyrightText: 2017 Mike Causer <https://github.com/mcauser> | ||
# SPDX-License-Identifier: MIT | ||
|
||
""" | ||
MicroPython P9813 RGB LED driver | ||
https://github.com/mcauser/micropython-p9813 | ||
""" | ||
|
||
from machine import Pin | ||
import p9813 | ||
|
||
# TinyPICO (esp32) | ||
clk = Pin(4, Pin.OUT) | ||
data = Pin(14, Pin.OUT) | ||
|
||
# Bit-banged, 10 LEDs, auto-write off | ||
num_leds = 10 | ||
chain = p9813.P9813(Pin(5), Pin(4), num_leds) | ||
chain = p9813.P9813_BITBANG(clk, data, num_leds, False) | ||
|
||
|
||
def fade(): | ||
for i in range(0, 4 * 256, 8): | ||
for j in range(num_leds): | ||
if (i // 256) % 2 == 0: | ||
val = i & 0xff | ||
else: | ||
val = 255 - (i & 0xff) | ||
chain[j] = (val, 0, 0) | ||
chain.write() | ||
for i in range(0, 4 * 256, 8): | ||
for j in range(num_leds): | ||
if (i // 256) % 2 == 0: | ||
val = i & 0xFF | ||
else: | ||
val = 255 - (i & 0xFF) | ||
chain[j] = (val, 0, 0) | ||
chain.write() | ||
|
||
|
||
# Fade in/out | ||
fade() |
Oops, something went wrong.