changed order

Signed-off-by: Ebbe Baß <ebbe@ping-mee.de>
master
Ebbe Baß 2022-07-27 15:46:21 +02:00
parent b64d7789b8
commit 4d2e67a29a
2 changed files with 52 additions and 41 deletions

91
main.py
View File

@ -155,49 +155,60 @@ if __name__ == '__main__':
mode = 3 mode = 3
elif payload == "Random Color per LED": elif payload == "Random Color per LED":
mode = 4 mode = 4
if os.path.isfile(current_path+r'/.env') == False:
# If not create it and add content
with open(current_path+r'/.env', 'w') as f:
var_lines = ["SPOTIPY_CLIENT_ID = ", "SPOTIPY_CLIENT_SECRET = ", "SPOTIPY_USER_NAME = ", "SPOTIPY_REDIRECT_URI = "]
for var_line in var_lines:
f.write(var_line+'\n')
print('Please fill out the variables in the .env file ( '+current_path+r'/.env )')
exit()
else:
load_dotenv()
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()
mode = 0 mode = 0
power = "True" power = "True"
global r global r
r = 255 r = 255
global g global g
g = 255 g = 255
global b global b
b = 255 b = 255
mqttBroker ="homeassistant.ping-mee.local" mqttBroker ="homeassistant.ping-mee.local"
client = mqtt.Client("server_rack_led") client = mqtt.Client("server_rack_led")
client.username_pw_set("mqtt", "pmMQTT_11!") client.username_pw_set("mqtt", "pmMQTT_11!")
debug_print("Connecting to MQTT Broker "+str(mqttBroker)) debug_print("Connecting to MQTT Broker "+str(mqttBroker))
client.connect(mqttBroker) client.connect(mqttBroker)
client.on_connect = mqtt_on_connect client.on_connect = mqtt_on_connect
client.on_message = mqtt_on_message client.on_message = mqtt_on_message
client.publish("server-rack-led/power", "True") client.publish("server-rack-led/power", "True")
client.publish("server-rack-led/mode", "Rainbow") client.publish("server-rack-led/mode", "Rainbow")
try: try:
client.loop_start() client.loop_start()
while True: while True:
if power == "True": if power == "True":
if mode == 0: if mode == 0:
rainbowCycle(strip) rainbowCycle(strip)
elif mode == 1: elif mode == 1:
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: elif mode == 3:
randomColor(strip) randomColor(strip)
elif mode == 4: elif mode == 4:
randomColorPerLED(strip) randomColorPerLED(strip)
else: else:
setColor(strip, Color(0,0,0)) setColor(strip, Color(0,0,0))
except KeyboardInterrupt: except KeyboardInterrupt:
client.publish("server-rack-led/power", "False") client.publish("server-rack-led/power", "False")
client.loop_stop() client.loop_stop()
setColor(strip, Color(0,0,0)) setColor(strip, Color(0,0,0))
GPIO.cleanup() GPIO.cleanup()

View File

@ -3,5 +3,5 @@ paho_mqtt==1.6.1
Pillow==9.2.0 Pillow==9.2.0
python-dotenv==0.20.0 python-dotenv==0.20.0
requests==2.28.1 requests==2.28.1
rpi_ws281x==4.3.4
spotipy==2.20.0 spotipy==2.20.0
rpi_ws281x==4.3.4