Update main.py
parent
bd8670261a
commit
0c4b88d34f
51
main.py
51
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:
|
||||||
|
|
||||||
|
@ -109,18 +109,21 @@ if __name__ == '__main__':
|
||||||
if led_power == False:
|
if led_power == False:
|
||||||
setColor(strip, Color(0,0,0))
|
setColor(strip, Color(0,0,0))
|
||||||
else:
|
else:
|
||||||
if idle_mode == '1':
|
if check_internet() == False:
|
||||||
rainbowCycle(strip)
|
blink(strip, Color(255,0,0), Color(255,255,255))
|
||||||
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:
|
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:
|
except KeyboardInterrupt:
|
||||||
setColor(strip, Color(0,0,0))
|
setColor(strip, Color(0,0,0))
|
Loading…
Reference in New Issue