From 0c4b88d34fcb9a55fed4b28ef760fead22bd173b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Tue, 9 Nov 2021 17:10:00 +0100 Subject: [PATCH] Update main.py --- main.py | 51 +++++++++++++++++++++++++++------------------------ 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/main.py b/main.py index 8b28f7b..4138a3c 100644 --- a/main.py +++ b/main.py @@ -14,6 +14,19 @@ LED_BRIGHTNESS = 255 # Set to 0 for darkest and 255 for brightest LED_INVERT = False # True to invert the signal (when using NPN transistor level shift) LED_CHANNEL = 0 # set to '1' for GPIOs 13, 19, 41, 45 or 53 +global led_power +global idle_mode +led_power = True + +try: + with open('./idle.txt', 'r') as f: + idle_mode = f.readline() +except: + with open('./idle.txt', 'w') as f: + f.write('1') + with open('./idle.txt', 'r') as f: + idle_mode = f.readline() + def check_internet(url='http://www.google.com/', timeout=5): try: _ = requests.head(url, timeout=timeout) @@ -81,19 +94,6 @@ if __name__ == '__main__': GPIO.add_event_detect(13, GPIO.BOTH, callback=led_power_toggle(), bouncetime=300) GPIO.add_event_detect(19, GPIO.BOTH, callback=change_idle_mode(), bouncetime=300) - global led_power - global idle_mode - led_power = True - - try: - with open('./idle.txt', 'r') as f: - idle_mode = f.readline() - except: - with open('./idle.txt', 'w') as f: - f.write('1') - with open('./idle.txt', 'r') as f: - idle_mode = f.readline() - try: while True: @@ -109,18 +109,21 @@ if __name__ == '__main__': if led_power == False: setColor(strip, Color(0,0,0)) else: - if idle_mode == '1': - rainbowCycle(strip) - elif idle_mode == '2': - setColor(strip, Color(255,0,0)) - elif idle_mode == '3': - setColor(strip, Color(0,255,0)) - elif idle_mode == '4': - setColor(strip, Color(0,0,255)) - elif idle_mode == '5': - setColor(strip, Color(125,245,255)) + if check_internet() == False: + blink(strip, Color(255,0,0), Color(255,255,255)) else: - blink(strip, Color(255,0,0), Color(0,0,0)) + if idle_mode == '1': + rainbowCycle(strip) + elif idle_mode == '2': + setColor(strip, Color(255,0,0)) + elif idle_mode == '3': + setColor(strip, Color(0,255,0)) + elif idle_mode == '4': + setColor(strip, Color(0,0,255)) + elif idle_mode == '5': + setColor(strip, Color(125,245,255)) + else: + blink(strip, Color(255,0,0), Color(0,0,0)) except KeyboardInterrupt: setColor(strip, Color(0,0,0)) \ No newline at end of file