From: Russ Handorf Date: Fri, 15 Feb 2019 02:28:57 +0000 (-0500) Subject: added button function X-Git-Url: https://handorf.org/code/?a=commitdiff_plain;h=HEAD;p=led-wall.git added button function --- diff --git a/README.md b/README.md index a313ae7..2482c3a 100644 --- a/README.md +++ b/README.md @@ -23,4 +23,4 @@ sudo python server.py *Potenial bugs* -1. I'm not entirely convinced the timeout to clear a pixel is making its way over. Might have to make a double check in the Python as well +*Fixed?* 1. I'm not entirely convinced the timeout to clear a pixel is making its way over. Might have to make a double check in the Python as well 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()