2015-05-02 01:58:10 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
# sets color of first neo pixel
|
2016-04-01 00:36:44 +02:00
|
|
|
|
2015-05-02 01:58:10 +02:00
|
|
|
import time
|
|
|
|
import sys
|
|
|
|
from math import *
|
2015-05-11 22:50:29 +02:00
|
|
|
import redis
|
2015-05-02 01:58:10 +02:00
|
|
|
|
|
|
|
from neopixel import *
|
|
|
|
|
|
|
|
# LED strip configuration:
|
2015-05-08 21:27:28 +02:00
|
|
|
LED_COUNT = 61 # Number of LED pixels.
|
2015-05-02 01:58:10 +02:00
|
|
|
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 = 100 # Set to 0 for darkest and 255 for brightest
|
|
|
|
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
|
|
|
|
|
2015-05-11 22:50:29 +02:00
|
|
|
def wheel(pos):
|
|
|
|
"""Generate rainbow colors across 0-255 positions."""
|
|
|
|
if pos < 85:
|
|
|
|
return Color(pos * 3, 255 - pos * 3, 0)
|
|
|
|
elif pos < 170:
|
|
|
|
pos -= 85
|
|
|
|
return Color(255 - pos * 3, 0, pos * 3)
|
|
|
|
else:
|
|
|
|
pos -= 170
|
|
|
|
return Color(0, pos * 3, 255 - pos * 3)
|
|
|
|
|
2015-05-08 21:27:28 +02:00
|
|
|
def clockcalc(value):
|
|
|
|
return 1+((30+int(value))%60)
|
|
|
|
|
2016-03-24 23:33:11 +01:00
|
|
|
def showit():
|
|
|
|
if ( valid == "yes" ):
|
|
|
|
strip.show()
|
|
|
|
|
2015-05-02 01:58:10 +02:00
|
|
|
# Main program logic follows:
|
|
|
|
if __name__ == '__main__':
|
2015-05-11 22:50:29 +02:00
|
|
|
# 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()
|
|
|
|
myredis=redis.StrictRedis(host='localhost', port=6379, db=0)
|
|
|
|
while True:
|
|
|
|
time.sleep(50/1000.0)
|
|
|
|
try:
|
|
|
|
r=int(myredis.get('neored'))
|
|
|
|
except:
|
|
|
|
r=0
|
|
|
|
try:
|
|
|
|
g=int(myredis.get('neogreen'))
|
|
|
|
except:
|
|
|
|
g=0
|
|
|
|
try:
|
|
|
|
b=int(myredis.get('neoblue'))
|
|
|
|
except:
|
|
|
|
b=0
|
|
|
|
try:
|
|
|
|
action=myredis.get('neoaction')
|
|
|
|
except:
|
|
|
|
action="set"
|
2016-03-24 23:33:11 +01:00
|
|
|
try:
|
|
|
|
valid=myredis.get('valid')
|
|
|
|
except:
|
|
|
|
valid="yes"
|
|
|
|
if ( valid != "yes" ):
|
|
|
|
continue
|
2015-05-11 22:50:29 +02:00
|
|
|
if(action == "set"):
|
2016-04-01 00:36:44 +02:00
|
|
|
print("Color set to: ",r,g,b)
|
2015-05-11 22:50:29 +02:00
|
|
|
for i in range(0,LED_COUNT):
|
|
|
|
strip.setPixelColor(i, Color(r,g,b))
|
2016-03-24 23:33:11 +01:00
|
|
|
showit()
|
|
|
|
if(action == "number"):
|
|
|
|
tmp=myredis.get('neovalue')
|
|
|
|
if(not tmp):
|
|
|
|
continue
|
|
|
|
i=clockcalc(int(tmp))
|
2016-04-01 00:36:44 +02:00
|
|
|
print("Digit ",i," set to: ",r,g,b)
|
2016-03-24 23:33:11 +01:00
|
|
|
strip.setPixelColor(i, Color(r,g,b))
|
|
|
|
showit()
|
2015-05-11 22:50:29 +02:00
|
|
|
if(action == "morse"):
|
2016-04-01 00:36:44 +02:00
|
|
|
print("Morsing with: ",r,g,b)
|
2015-05-02 01:58:10 +02:00
|
|
|
speed=10
|
2015-05-11 22:50:29 +02:00
|
|
|
for i in range(0,LED_COUNT):
|
|
|
|
strip.setPixelColor(i, Color(0,0,0))
|
2016-03-24 23:33:11 +01:00
|
|
|
morsecode=myredis.get('neovalue')
|
2015-05-11 22:50:29 +02:00
|
|
|
morsep=1
|
2015-05-02 01:58:10 +02:00
|
|
|
for c in morsecode:
|
|
|
|
if c==".":
|
2015-05-11 22:50:29 +02:00
|
|
|
strip.setPixelColor(morsep, Color(r,g,b))
|
|
|
|
morsep+=1
|
|
|
|
strip.setPixelColor(morsep, Color(0,0,0))
|
|
|
|
morsep+=1
|
2015-05-02 01:58:10 +02:00
|
|
|
if c=="-":
|
2015-05-11 22:50:29 +02:00
|
|
|
strip.setPixelColor(morsep, Color(r,g,b))
|
|
|
|
morsep+=1
|
|
|
|
strip.setPixelColor(morsep, Color(r,g,b))
|
|
|
|
morsep+=1
|
|
|
|
strip.setPixelColor(morsep, Color(0,0,0))
|
|
|
|
morsep+=1
|
|
|
|
strip.setPixelColor(morsep, Color(0,0,0))
|
|
|
|
morsep+=1
|
2015-05-02 01:58:10 +02:00
|
|
|
if c==" ":
|
2015-05-11 22:50:29 +02:00
|
|
|
strip.setPixelColor(morsep, Color(0,0,0))
|
|
|
|
morsep+=1
|
|
|
|
strip.setPixelColor(morsep, Color(0,0,0))
|
|
|
|
morsep+=1
|
|
|
|
strip.setPixelColor(morsep, Color(0,0,0))
|
|
|
|
morsep+=1
|
|
|
|
strip.setPixelColor(morsep, Color(0,0,0))
|
|
|
|
morsep+=1
|
2016-03-24 23:33:11 +01:00
|
|
|
showit()
|
2015-05-11 22:50:29 +02:00
|
|
|
time.sleep(1)
|
|
|
|
if(action == "pulse"):
|
2016-04-01 00:36:44 +02:00
|
|
|
print("Pulsing with: ",r,g,b)
|
2015-05-02 01:58:10 +02:00
|
|
|
pulsewidth=50
|
2015-05-11 22:50:29 +02:00
|
|
|
while (action==myredis.get('neoaction')):
|
2015-05-02 01:58:10 +02:00
|
|
|
for i in range(pulsewidth):
|
2015-05-11 22:50:29 +02:00
|
|
|
if(action!=myredis.get('neoaction')):
|
|
|
|
break
|
2016-03-31 20:43:28 +02:00
|
|
|
# reset all pixels to black
|
2015-05-08 21:27:28 +02:00
|
|
|
color=Color(0,0,0)
|
|
|
|
for j in range(0,60):
|
|
|
|
strip.setPixelColor(clockcalc(j), color)
|
2016-03-31 20:43:28 +02:00
|
|
|
# put the hours hand as white, skew by 5 depending on minutes value
|
|
|
|
clockpos=int(int(time.strftime('%I',time.localtime()))*5+int(time.strftime('%M',time.localtime()))/60*5)
|
2015-05-08 21:27:28 +02:00
|
|
|
for j in range(-2,3):
|
|
|
|
strip.setPixelColor(clockcalc(clockpos+j),Color(30,30,30))
|
2016-03-31 20:43:28 +02:00
|
|
|
# set the hours marks as a plusing blue
|
|
|
|
trigo=sin(i/pulsewidth*pi)
|
|
|
|
color=Color(int(r*trigo),int(g*trigo),int(b*trigo))
|
2015-05-08 21:27:28 +02:00
|
|
|
for j in range(0,60,5):
|
|
|
|
strip.setPixelColor(clockcalc(j), color)
|
2016-03-31 20:43:28 +02:00
|
|
|
# put the current people count as magenta
|
|
|
|
strip.setPixelColor(clockcalc(myredis.get('neocounter')),Color(10,0,10))
|
|
|
|
# put the minute hand as red
|
2015-05-08 21:27:28 +02:00
|
|
|
strip.setPixelColor(clockcalc(time.strftime('%M',time.localtime())),Color(30,0,0))
|
2016-03-31 20:43:28 +02:00
|
|
|
# put the seconds hand as green
|
2015-05-08 21:27:28 +02:00
|
|
|
strip.setPixelColor(clockcalc(time.strftime('%S',time.localtime())),Color(0,30,0))
|
2016-03-24 23:33:11 +01:00
|
|
|
showit()
|
2015-05-02 01:58:10 +02:00
|
|
|
time.sleep(50/1000.0)
|
2015-05-11 22:50:29 +02:00
|
|
|
|
|
|
|
if(action == "flash"):
|
2016-04-01 00:36:44 +02:00
|
|
|
print("Flashing with: ",r,g,b)
|
|
|
|
print(myredis.get('neoaction'))
|
2015-05-11 22:50:29 +02:00
|
|
|
wait_ms=50
|
|
|
|
"""Rainbow movie theater light style chaser animation."""
|
|
|
|
while (action==myredis.get('neoaction')):
|
2016-04-01 00:36:44 +02:00
|
|
|
print(" Flashing with: ",r,g,b)
|
2015-05-11 22:50:29 +02:00
|
|
|
for j in range(256):
|
2016-04-01 00:36:44 +02:00
|
|
|
print(" Flashing with: ",r,g,b)
|
2015-05-11 22:50:29 +02:00
|
|
|
if(action!=myredis.get('neoaction')):
|
|
|
|
break
|
|
|
|
for q in range(3):
|
|
|
|
for i in range(0, strip.numPixels(), 3):
|
|
|
|
strip.setPixelColor(i+q, wheel((i+j) % 255))
|
2016-03-24 23:33:11 +01:00
|
|
|
showit()
|
2015-05-11 22:50:29 +02:00
|
|
|
time.sleep(wait_ms/1000.0)
|
|
|
|
for i in range(0, strip.numPixels(), 3):
|
|
|
|
strip.setPixelColor(i+q, 0)
|
|
|
|
|