Skip to content

Instantly share code, notes, and snippets.

@fvdbosch
Last active August 27, 2015 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fvdbosch/b82626fd7f3ee862b70c to your computer and use it in GitHub Desktop.
Save fvdbosch/b82626fd7f3ee862b70c to your computer and use it in GitHub Desktop.
PiDesk LED Animations
#!/usr/bin/python3
#
# PiDesk LED Animation script
#
# Make the necessary imports
import time
from neopixel import *
import sys
# LED strip configuration:
LED_COUNT = 121 # Number of LED pixels.
LED_PIN = 12 # 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 = 255 # Set to 0 for darkest and 255 for brightest
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
# Define functions which animate LEDs in various ways.
def sweepColor(strip, color, wait_ms=50): # start lighting up from the middle of the strip
for i in range(strip.numPixels()/2):
strip.setPixelColor((strip.numPixels()/2)+i, color)
strip.setPixelColor((strip.numPixels()/2)-i, color)
strip.show()
time.sleep(wait_ms/1000.0)
for i in range(strip.numPixels()/2):
strip.setPixelColor((strip.numPixels()/2)+i, Color(0, 0, 0))
strip.setPixelColor((strip.numPixels()/2)-i, Color(0, 0, 0))
strip.show()
time.sleep(wait_ms/1000.0)
def pulseWhite(strip, brightness, wait_ms=50): # gradually increase brightness, gradually decrease it
for j in range(0, brightness):
for i in range(strip.numPixels()):
strip.setPixelColor(i, Color(0+j, 0+j, 0+j))
strip.show()
time.sleep(wait_ms/1000.0)
for j in range(0, brightness):
for i in range(strip.numPixels()):
strip.setPixelColor(i, Color(brightness-j, brightness-j, brightness-j))
strip.show()
time.sleep(wait_ms/1000.0)
def colorWipe(strip, color, wait_ms=50): # set all pixels to a certain color
for i in range(strip.numPixels()):
strip.setPixelColor(i, color)
strip.show()
time.sleep(wait_ms/1000.0)
# Create NeoPixel object with appropriate configuration.
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS)
# Intialize the library (must be called once before other functions).
strip.begin()
if(sys.argv[1] == "pulse"): # if first argument is "pulse", execute pulse function
for i in range(35): # repeat 35 times, time required for screen to pop in or out of desk
pulseWhite(strip,int(sys.argv[2]), 20)
elif(sys.argv[1] == "sweep"): # if first argument is "sweep", execute sweep function with passed r, g, b values
for i in range(35): # repeat 35 times, time required for screen to pop in or out of desk
sweepColor(strip,Color(int(sys.argv[2]), int(sys.argv[3]), int(sys.argv[4])),10)
else: # if first argument is anything else, turn off all leds
colorWipe(strip, Color(0, 0, 0), 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment