Updated everything

master
Ebbe Baß 2021-11-09 23:16:38 +01:00
parent f2b8ea7efa
commit 8148458496
2 changed files with 30 additions and 55 deletions

83
main.py
View File

@ -14,19 +14,6 @@ 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 led_power_toggler
led_power_toggler = True
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')
idle_mode = 1
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)
@ -35,7 +22,6 @@ def check_internet(url='http://www.google.com/', timeout=5):
return False return False
def wheel(pos): def wheel(pos):
"""Generate rainbow colors across 0-255 positions."""
if pos < 85: if pos < 85:
return Color(pos * 3, 255 - pos * 3, 0) return Color(pos * 3, 255 - pos * 3, 0)
elif pos < 170: elif pos < 170:
@ -45,8 +31,7 @@ def wheel(pos):
pos -= 170 pos -= 170
return Color(0, pos * 3, 255 - pos * 3) return Color(0, pos * 3, 255 - pos * 3)
def rainbowCycle(strip, wait_ms=10, iterations=10): def rainbowCycle(strip, wait_ms=5, iterations=10):
"""Draw rainbow that uniformly distributes itself across all pixels."""
for j in range(256*iterations): for j in range(256*iterations):
for i in range(strip.numPixels()): for i in range(strip.numPixels()):
strip.setPixelColor(i, wheel((int(i * 256 / strip.numPixels()) + j) & 255)) strip.setPixelColor(i, wheel((int(i * 256 / strip.numPixels()) + j) & 255))
@ -69,29 +54,20 @@ def blink(strip, color1, color2, iterations=10, wait_ms=10):
strip.show() strip.show()
time.sleep(1) time.sleep(1)
def read_idle():
with open('./idle.txt', 'r') as f:
idle_mode = f.readline()
def change_idle_mode(channel): def change_idle_mode(channel):
global idle_mode global idle_mode
with open('./idle.txt', 'r') as f: idle_mode += 1
idle_mode = f.readline() if idle_mode == 6:
if int(idle_mode) > 7: idle_mode = 1
idle_mode = 0
with open('./idle.txt', 'w') as f:
f.write(int(idle_mode) + 1)
with open('./idle.txt', 'r') as f:
idle_mode = f.readline()
print('Change Idle-Mode: '+idle_mode)
def power_toggle(channel): def power_toggle(channel):
if led_power == True: print('button pressed')
led_power_toggler = False global power_button_pressed
else: power_button_pressed = 'True'
led_power_toggler = True
if __name__ == '__main__': if __name__ == '__main__':
led_power = 'True'
idle_mode = 1
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()
GPIO.setmode(GPIO.BOARD) GPIO.setmode(GPIO.BOARD)
@ -102,41 +78,40 @@ if __name__ == '__main__':
try: try:
while True: while True:
led_power = led_power_toggler
try: try:
with open('./idle.txt', 'r') as f: print('Button pressed: '+str(power_button_pressed))
idle_mode = f.readline() if str(power_button_pressed) == 'True':
if led_power == 'True':
led_power = 'False'
power_button_pressed = 'False'
else:
led_power = 'True'
power_button_pressed = 'False'
except: except:
with open('./idle.txt', 'w') as f: pass
f.write('1')
with open('./idle.txt', 'r') as f:
idle_mode = f.readline()
if power_toggle == False: if led_power == 'True':
print('Power: False')
setColor(strip, Color(0,0,0))
led_power == False
else:
print('Power: True') print('Power: True')
led_power == True
if check_internet() == False: if check_internet() == False:
blink(strip, Color(255,0,0), Color(255,255,255)) blink(strip, Color(255,0,0), Color(255,255,255))
else: else:
print(idle_mode) if idle_mode == 1:
if idle_mode == '1':
rainbowCycle(strip) rainbowCycle(strip)
elif idle_mode == '2': elif idle_mode == 2:
setColor(strip, Color(255,0,0)) setColor(strip, Color(255,0,0))
elif idle_mode == '3': elif idle_mode == 3:
setColor(strip, Color(0,255,0)) setColor(strip, Color(0,255,0))
elif idle_mode == '4': elif idle_mode == 4:
setColor(strip, Color(0,0,255)) setColor(strip, Color(0,0,255))
elif idle_mode == '5': elif idle_mode == 5:
setColor(strip, Color(125,245,255)) setColor(strip, Color(125,245,255))
else: else:
blink(strip, Color(255,0,0), Color(0,0,0)) blink(strip, Color(255,0,0), Color(0,0,0))
time.sleep(1)
else:
print('Power: False')
setColor(strip, Color(0,0,0))
time.sleep(1)
except KeyboardInterrupt: except KeyboardInterrupt:
setColor(strip, Color(0,0,0)) setColor(strip, Color(0,0,0))
GPIO.cleanup() GPIO.cleanup()

View File

@ -55,6 +55,6 @@ if __name__ == '__main__':
while True: while True:
#blink(strip, Color(255,0,0), Color(255,255,255)) #blink(strip, Color(255,0,0), Color(255,255,255))
#setColor(strip, Color(255,0,0)) #setColor(strip, Color(255,0,0))
#rainbowCycle(strip) rainbowCycle(strip)
except KeyboardInterrupt: except KeyboardInterrupt:
setColor(strip, Color(0,0,0)) setColor(strip, Color(0,0,0))