Commit ad3c5af0 authored by Aljaž Srebrnič's avatar Aljaž Srebrnič

Make leds go blinky blinky

parent e55c3f12
#!/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()
# 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 light_flame():
spi = spidev.SpiDev()
spi.open(1, 0)
port = "5556"
if len(sys.argv) > 1:
port = sys.argv[1]
int(port)
while True:
ws2812.write2812(spi, [get_color()])
sleep(0.2)
# Socket to talk to server
context = zmq.Context()
socket = context.socket(zmq.SUB)
print("Connecting to coordinator...")
socket.connect(f"tcp://localhost:{port}")
def main():
port = "5556"
if len(sys.argv) > 1:
port = sys.argv[1]
int(port)
topicfilter = "events"
socket.setsockopt(zmq.SUBSCRIBE, topicfilter)
# Socket to talk to server
context = zmq.Context()
socket = context.socket(zmq.SUB)
print("Connecting to coordinator...")
socket.connect(f"tcp://localhost:{port}")
while True:
string = socket.recv()
topic, messagedata = string.split()
print(topic, messagedata)
topicfilter = "events"
socket.setsockopt(zmq.SUBSCRIBE, topicfilter)
if messagedata == "liftoff":
light_flame()
elif messagedata == "stage_1_separation":
light_flame()
else:
print("Unhandled message")
while True:
string = socket.recv()
topic, messagedata = string.split()
print(topic, messagedata)
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()
if messagedata == "liftoff":
light_flame()
elif messagedata == "stage_1_separation":
light_flame()
else:
print("Unhandled message")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment