Loading lighting.py +46 −53 Original line number Diff line number Diff line #!/usr/bin/env python3 import zmq import sys import OPi.GPIO as GPIO from neopixel import * from time import sleep from random import randint GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.OUT) import zmq import spidev import ws2812 def get_color(): rand = randint(0, 10) if rand < 5: return (255, 248, 255) elif rand == 6: return (255, 111, 0) elif rand == 7: return (255, 234, 0) elif rand == 8: return (255, 87, 34) else: return (213, 0, 0) # Create NeoPixel object with appropriate configuration. strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT) # Intialize the library (must be called once before other functions). strip.begin() def light_flame(): spi = spidev.SpiDev() spi.open(1, 0) while True: ws2812.write2812(spi, [get_color()]) sleep(0.2) # LED strip configuration: LED_COUNT = 16 # Number of LED pixels. LED_PIN = 18 # GPIO pin connected to the pixels (must support PWM!). LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz) LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest LED_DMA = 5 # DMA channel to use for generating signal (try 5) LED_INVERT = False # True to invert the signal (when using NPN transistor level shift) def main(): port = "5556" if len(sys.argv) > 1: port = sys.argv[1] Loading @@ -38,7 +48,6 @@ socket.connect(f"tcp://localhost:{port}") topicfilter = "events" socket.setsockopt(zmq.SUBSCRIBE, topicfilter) while True: string = socket.recv() topic, messagedata = string.split() Loading @@ -50,19 +59,3 @@ while True: light_flame() else: print("Unhandled message") def light_flame(): for i in range(0,strip.numPixels(),1): rand = randint(0,10) if rand<5: color = (255, 248, 255) else if rand==6: color = (255, 111, 0) else if rand==7: color = (255, 234, 0) else if rand==8: color = (255, 87, 34) else : color = (213, 0, 0) strip.setPixelColor(i, color) strip.show() Loading
lighting.py +46 −53 Original line number Diff line number Diff line #!/usr/bin/env python3 import zmq import sys import OPi.GPIO as GPIO from neopixel import * from time import sleep from random import randint GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.OUT) import zmq import spidev import ws2812 def get_color(): rand = randint(0, 10) if rand < 5: return (255, 248, 255) elif rand == 6: return (255, 111, 0) elif rand == 7: return (255, 234, 0) elif rand == 8: return (255, 87, 34) else: return (213, 0, 0) # Create NeoPixel object with appropriate configuration. strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT) # Intialize the library (must be called once before other functions). strip.begin() def light_flame(): spi = spidev.SpiDev() spi.open(1, 0) while True: ws2812.write2812(spi, [get_color()]) sleep(0.2) # LED strip configuration: LED_COUNT = 16 # Number of LED pixels. LED_PIN = 18 # GPIO pin connected to the pixels (must support PWM!). LED_FREQ_HZ = 800000 # LED signal frequency in hertz (usually 800khz) LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest LED_DMA = 5 # DMA channel to use for generating signal (try 5) LED_INVERT = False # True to invert the signal (when using NPN transistor level shift) def main(): port = "5556" if len(sys.argv) > 1: port = sys.argv[1] Loading @@ -38,7 +48,6 @@ socket.connect(f"tcp://localhost:{port}") topicfilter = "events" socket.setsockopt(zmq.SUBSCRIBE, topicfilter) while True: string = socket.recv() topic, messagedata = string.split() Loading @@ -50,19 +59,3 @@ while True: light_flame() else: print("Unhandled message") def light_flame(): for i in range(0,strip.numPixels(),1): rand = randint(0,10) if rand<5: color = (255, 248, 255) else if rand==6: color = (255, 111, 0) else if rand==7: color = (255, 234, 0) else if rand==8: color = (255, 87, 34) else : color = (213, 0, 0) strip.setPixelColor(i, color) strip.show()