parent
3d0c6561a8
commit
11e8ce8800
42
main.py
42
main.py
|
@ -32,6 +32,39 @@ def debug_print(message: str):
|
|||
current_time = now.strftime("%H:%M:%S")
|
||||
print('[DEBUG]['+current_time+'] '+message)
|
||||
|
||||
def fade_in_animation(strip, mode, color):
|
||||
if mode == 0:
|
||||
for j in range(256*10):
|
||||
if mode > 0:
|
||||
break
|
||||
elif power == "False":
|
||||
break
|
||||
for i in range(strip.numPixels()):
|
||||
strip.setPixelColor(i, wheel((int(i * 256 / strip.numPixels()) + j) & 255))
|
||||
strip.show()
|
||||
elif mode == 1:
|
||||
for i in range(strip.numPixels()):
|
||||
strip.setPixelColor(i, color)
|
||||
strip.show()
|
||||
time.sleep(float(0.01))
|
||||
elif mode == 2:
|
||||
for i in range(strip.numPixels()):
|
||||
strip.setPixelColor(i, color)
|
||||
strip.show()
|
||||
time.sleep(float(0.01))
|
||||
elif mode == 3:
|
||||
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(float(0.01))
|
||||
time.sleep(1)
|
||||
elif mode == 4:
|
||||
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 wheel(pos):
|
||||
if pos < 85:
|
||||
return Color(pos * 3, 255 - pos * 3, 0)
|
||||
|
@ -90,6 +123,8 @@ def mqtt_on_connect(client, userdata, flags, rc):
|
|||
|
||||
|
||||
if __name__ == '__main__':
|
||||
global singleExecute
|
||||
singleExecute = True
|
||||
def mqtt_on_message(client, userdata, msg):
|
||||
print("topic: " ,str(msg.topic))
|
||||
print("payload: " ,str(msg.payload.decode("utf-8")))
|
||||
|
@ -98,6 +133,7 @@ if __name__ == '__main__':
|
|||
if topic == "server-rack-led/power":
|
||||
global power
|
||||
power = payload
|
||||
singleExecute = True
|
||||
|
||||
elif topic == "server-rack-led/rgb":
|
||||
splitted_payload = payload.split(",")
|
||||
|
@ -148,6 +184,10 @@ if __name__ == '__main__':
|
|||
client.loop_start()
|
||||
while True:
|
||||
if power == "True":
|
||||
if singleExecute == True:
|
||||
fade_in_animation(strip, mode, Color(int(r), int(g), int(b)))
|
||||
singleExecute = False
|
||||
|
||||
if mode == 0:
|
||||
rainbowCycle(strip)
|
||||
elif mode == 1:
|
||||
|
@ -159,6 +199,8 @@ if __name__ == '__main__':
|
|||
elif mode == 4:
|
||||
randomColorPerLED(strip)
|
||||
else:
|
||||
if singleExecute == True:
|
||||
singleExecute = False
|
||||
setColor(strip, Color(0,0,0))
|
||||
|
||||
except KeyboardInterrupt:
|
||||
|
|
Loading…
Reference in New Issue