Last active
November 20, 2021 01:38
-
-
Save todbot/308fd1de936c1670194528362a815efb to your computer and use it in GitHub Desktop.
Demonstrate doing 2-wire Neopixel strip with CircuitPython
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
# neopixel_2wire_code.py -- demonstrate doing 2-wire Neopixel strip | |
# Tested on ItsyBitsy 2040 with CircuitPython 7.0 | |
# To modify your strip to be a 2-wire strip: | |
# - Put a Shottkey diode across Din -> Vin | |
# - Put a 10uF capacitor across Vin & Gnd | |
# - Run two wires from microcontroller : Din + Ground | |
# - Data line can be a 3V3 pin but a 5V pin works better | |
# - Only drive about 4 LEDs on a single pin | |
# - Brightness can be only about 20% max | |
# | |
# 2021 - @todbot / Tod Kurt | |
# More info: https://twitter.com/todbot/status/1461838809662779392 | |
# | |
import random, time | |
import board | |
import neopixel, rainbowio | |
led = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.4) # onboard LED | |
leds = neopixel.NeoPixel(board.D5, 4, brightness=0.1, auto_write=False) # our 2-wire strip | |
def leds_show(): | |
leds.pin.value = False # drop pin low so WS2812 protocol starts correctly | |
leds.show() | |
leds.pin.value = True # raise pin high so strip stays powered | |
n = 0 | |
while True: | |
# simple moving rainbow on strip | |
for i in range(len(leds)): | |
color = rainbowio.colorwheel( (i*256)/len(leds) + n ) | |
leds[i] = color | |
leds_show() | |
n = (n+1) % 1000 | |
led.fill( color ) # show last color on on-board neopixel | |
time.sleep(0.01) | |
# print("%d:%6x" % (n, color) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment