From 84334e14fdb0f430d4cbe3d57fa14acf6d5bdf6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ebbe=20Ba=C3=9F?= Date: Tue, 9 Nov 2021 19:38:49 +0100 Subject: [PATCH] Update main.py --- main.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/main.py b/main.py index 0165e23..3e8ccd2 100644 --- a/main.py +++ b/main.py @@ -14,6 +14,7 @@ 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 led_power = True try: @@ -66,15 +67,6 @@ def blink(strip, color1, color2, iterations=10, wait_ms=10): strip.show() time.sleep(1) -def led_power_toggle(channel): - global led_power - if led_power == True: - led_power = False - return False - else: - led_power = True - return True - def read_idle(): with open('./idle.txt', 'r') as f: idle_mode = f.readline() @@ -91,8 +83,11 @@ def change_idle_mode(channel): idle_mode = f.readline() print('Change Idle-Mode: '+idle_mode) -def test(): - print('test') +def power_toggle(): + if led_power == True: + return False + else: + return True if __name__ == '__main__': strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, LED_FREQ_HZ, LED_DMA, LED_INVERT, LED_BRIGHTNESS, LED_CHANNEL) @@ -100,7 +95,7 @@ if __name__ == '__main__': GPIO.setmode(GPIO.BOARD) GPIO.setup(13, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(19, GPIO.IN, pull_up_down=GPIO.PUD_UP) - GPIO.add_event_detect(13, GPIO.RISING, callback=led_power_toggle, bouncetime=300) + GPIO.add_event_detect(13, GPIO.RISING, callback=power_toggle, bouncetime=300) GPIO.add_event_detect(19, GPIO.RISING, callback=change_idle_mode, bouncetime=300) try: @@ -114,11 +109,12 @@ if __name__ == '__main__': with open('./idle.txt', 'r') as f: idle_mode = f.readline() - print(led_power_toggle) - - if led_power_toggle == False: + if power_toggle == False: setColor(strip, Color(0,0,0)) + led_power == False + else: + led_power == True if check_internet() == False: blink(strip, Color(255,0,0), Color(255,255,255)) else: