Update main.py
parent
bd8670261a
commit
0c4b88d34f
29
main.py
29
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_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
|
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):
|
def check_internet(url='http://www.google.com/', timeout=5):
|
||||||
try:
|
try:
|
||||||
_ = requests.head(url, timeout=timeout)
|
_ = 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(13, GPIO.BOTH, callback=led_power_toggle(), bouncetime=300)
|
||||||
GPIO.add_event_detect(19, GPIO.BOTH, callback=change_idle_mode(), 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:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
|
||||||
|
@ -108,6 +108,9 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
if led_power == False:
|
if led_power == False:
|
||||||
setColor(strip, Color(0,0,0))
|
setColor(strip, Color(0,0,0))
|
||||||
|
else:
|
||||||
|
if check_internet() == False:
|
||||||
|
blink(strip, Color(255,0,0), Color(255,255,255))
|
||||||
else:
|
else:
|
||||||
if idle_mode == '1':
|
if idle_mode == '1':
|
||||||
rainbowCycle(strip)
|
rainbowCycle(strip)
|
||||||
|
|
Loading…
Reference in New Issue