From 386d81fc09f08bbc7455d3261f62ea22c606da6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Wed, 27 Jul 2022 15:25:04 +0200 Subject: [PATCH] added random color MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Ebbe Baß --- main.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main.py b/main.py index 6ccf4c5..7cb52f4 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ from base64 import b16decode import time from datetime import datetime +from random import * try: from rpi_ws281x import * import RPi.GPIO as GPIO @@ -68,6 +69,12 @@ def strobe(strip, color): strip.show() time.sleep(float(0.05)) +def randomColor(strip): + for i in range(strip.numPixels()): + strip.setPixelColor(i, Color(randint(0, 255), randint(0, 255), randint(0, 255))) + 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") @@ -101,6 +108,8 @@ if __name__ == '__main__': mode = 1 elif payload == "Strobe": mode = 2 + elif payload == "Random Color": + mode = 3 strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) strip.begin() @@ -135,6 +144,8 @@ if __name__ == '__main__': setColor(strip, Color(int(r), int(g), int(b))) elif mode == 2: strobe(strip, Color(int(r), int(g), int(b))) + elif mode == 3: + randomColor(strip) else: setColor(strip, Color(0,0,0))