added static color update animation and random color per led
Signed-off-by: Ebbe Baß <ebbe@ping-mee.de>master
parent
386d81fc09
commit
5871608510
12
main.py
12
main.py
|
@ -57,6 +57,7 @@ def setColor(strip, color, wait_ms=10):
|
|||
for i in range(strip.numPixels()):
|
||||
strip.setPixelColor(i, color)
|
||||
strip.show()
|
||||
time.sleep(float(0.01))
|
||||
time.sleep(wait_ms/1000.0)
|
||||
|
||||
def strobe(strip, color):
|
||||
|
@ -75,6 +76,13 @@ def randomColor(strip):
|
|||
strip.show()
|
||||
time.sleep(1)
|
||||
|
||||
def randomColorPerLED(strip):
|
||||
color = Color(randint(0, 255), randint(0, 255), randint(0, 255))
|
||||
for i in range(strip.numPixels()):
|
||||
strip.setPixelColor(i, color)
|
||||
strip.show()
|
||||
time.sleep(1)
|
||||
|
||||
def mqtt_on_connect(client, userdata, flags, rc):
|
||||
client.subscribe("server-rack-led/power")
|
||||
client.subscribe("server-rack-led/mode")
|
||||
|
@ -110,6 +118,8 @@ if __name__ == '__main__':
|
|||
mode = 2
|
||||
elif payload == "Random Color":
|
||||
mode = 3
|
||||
elif payload == "Random Color per LED":
|
||||
mode = 4
|
||||
|
||||
strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
|
||||
strip.begin()
|
||||
|
@ -146,6 +156,8 @@ if __name__ == '__main__':
|
|||
strobe(strip, Color(int(r), int(g), int(b)))
|
||||
elif mode == 3:
|
||||
randomColor(strip)
|
||||
elif mode == 4:
|
||||
randomColorPerLED(strip)
|
||||
else:
|
||||
setColor(strip, Color(0,0,0))
|
||||
|
||||
|
|
Loading…
Reference in New Issue