import threading
import time
from neopixel import *
+import RPi.GPIO as GPIO
+import time
+
+GPIO.setmode(GPIO.BCM)
+
+GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_UP)
LED_COUNT = 1024 # Number of LED pixels.
LED_PIN = 18 # GPIO pin connected to the pixels (18 uses PWM!).
LED_INVERT = False # True to invert the signal (when using NPN transistor level shift)
LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53
+on = True
+
bind_ip = '0.0.0.0'
bind_port = 10000
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
pixel_status.append(0)
strip.show()
-
print "Starting Server"
def led_timeout(strip,pixel):
strip.setPixelColor(i, Color(0,0,0))
while True:
+ input_state = GPIO.input(17)
+ if input_state == False:
+ if on == True:
+ on = False
+ for i in range(1024):
+ strip.setPixelColor(i, Color(0,0,0))
+ strip.show()
+ else:
+ on = True
+ for i in range(1024):
+ strip.setPixelColor(i, pixels[i])
+ time.sleep(0.5)
+
data, addr = server.recvfrom(1024)
if data:
- #print 'Received {}'.format(data)
elements=format(data).split(",")
+ if len(elements)>2:
+ print "Kill the sniffer and start over"
+ exit(0)
color=elements[0].split(":")
pixel_color=pixels[int(color[1])]
red=pixel_color[0]
if color[0]=="B":
strip.setPixelColor(int(color[1]), Color(green, red, int(elements[1])))
pixels[int(color[1])] =(red,green,int(elements[1]))
+
+ if on==True:
strip.show()