parent
9d2d931aa9
commit
386d81fc09
11
main.py
11
main.py
|
@ -1,6 +1,7 @@
|
||||||
from base64 import b16decode
|
from base64 import b16decode
|
||||||
import time
|
import time
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from random import *
|
||||||
try:
|
try:
|
||||||
from rpi_ws281x import *
|
from rpi_ws281x import *
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
|
@ -68,6 +69,12 @@ def strobe(strip, color):
|
||||||
strip.show()
|
strip.show()
|
||||||
time.sleep(float(0.05))
|
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):
|
def mqtt_on_connect(client, userdata, flags, rc):
|
||||||
client.subscribe("server-rack-led/power")
|
client.subscribe("server-rack-led/power")
|
||||||
client.subscribe("server-rack-led/mode")
|
client.subscribe("server-rack-led/mode")
|
||||||
|
@ -101,6 +108,8 @@ if __name__ == '__main__':
|
||||||
mode = 1
|
mode = 1
|
||||||
elif payload == "Strobe":
|
elif payload == "Strobe":
|
||||||
mode = 2
|
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 = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL)
|
||||||
strip.begin()
|
strip.begin()
|
||||||
|
@ -135,6 +144,8 @@ if __name__ == '__main__':
|
||||||
setColor(strip, Color(int(r), int(g), int(b)))
|
setColor(strip, Color(int(r), int(g), int(b)))
|
||||||
elif mode == 2:
|
elif mode == 2:
|
||||||
strobe(strip, Color(int(r), int(g), int(b)))
|
strobe(strip, Color(int(r), int(g), int(b)))
|
||||||
|
elif mode == 3:
|
||||||
|
randomColor(strip)
|
||||||
else:
|
else:
|
||||||
setColor(strip, Color(0,0,0))
|
setColor(strip, Color(0,0,0))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue