Skip to content

Instantly share code, notes, and snippets.

@alextea
Created December 3, 2016 16:08
Show Gist options
  • Save alextea/80aff4fd1adbd71ad95cfd6bb27354c0 to your computer and use it in GitHub Desktop.
Save alextea/80aff4fd1adbd71ad95cfd6bb27354c0 to your computer and use it in GitHub Desktop.
Cycle through R, G and B on a single neopixel
# NeoPixel library strandtest example
# Author: Tony DiCola ([email protected])
#
# Direct port of the Arduino NeoPixel library strandtest example. Showcases
# various animations on a strip of NeoPixels.
import time
from neopixel import *
# LED strip configuration:
LED_COUNT = 50 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (must support PWM!).
LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz)
LED_DMA = 5 # DMA channel to use for generating signal (try 5)
LED_BRIGHTNESS = 10 # Set to 0 for darkest and 255 for brightest
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
LED_STRIP = ws.WS2811_STRIP_BRG
# Define functions which animate LEDs in various ways.
def rgb_test(strip, wait_ms=500):
rgb = [Color(255, 0, 0), Color(0, 255, 0), Color(0, 0, 255)]
while True:
for i in range(len(rgb)):
print i, rgb[i]
strip.setPixelColor(0, rgb[i])
strip.show()
time.sleep(wait_ms/1000.0)
# Main program logic follows:
if __name__ == '__main__':
# Create NeoPixel object with appropriate configuration.
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, 0, LED_STRIP)
# Intialize the library (must be called once before other functions).
strip.begin()
print ('Press Ctrl-C to quit.')
rgb_test(strip)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment