X-Git-Url: http://russells-world.com/code/?p=led-wall.git;a=blobdiff_plain;f=server.py;fp=server.py;h=5167904a66fddeb92cfdbee422bbd38b429967b9;hp=467cf0f1c56c5704a35ad807fbf3a69136b4662e;hb=bdf89a056fc49b80e06597775353255ee5069e5a;hpb=7faf6e4d7297e6046392af4e7a0c225f3c080f9d diff --git a/server.py b/server.py index 467cf0f..5167904 100644 --- a/server.py +++ b/server.py @@ -2,6 +2,12 @@ import socket 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!). @@ -12,6 +18,8 @@ LED_BRIGHTNESS = 128 # Set to 0 for darkest and 255 for brightest 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) @@ -31,7 +39,6 @@ for i in range(1024): pixel_status.append(0) strip.show() - print "Starting Server" def led_timeout(strip,pixel): @@ -41,10 +48,25 @@ 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] @@ -62,4 +84,6 @@ while True: 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()