using datetime for color change scheduling

This commit is contained in:
Mikey Sklar 2019-02-15 16:46:12 -07:00
parent e277426e74
commit 6fa258c245
2 changed files with 38 additions and 17 deletions

View file

@ -1,28 +1,49 @@
import datetime
import time
import board
import neopixel
import sys
import datetime
pi_pin = board.D18
numpix = 144
brightness = 1.0
pixels = neopixel.NeoPixel(pi_pin, numpix, brightness=brightness) # Raspberry Pi wiring!
pixels = neopixel.NeoPixel(pi_pin, numpix, brightness=brightness)
# valid argument check and color assignment
# morning == blue
# night == red
# off == all LEDs off
if len(sys.argv) == 2:
if sys.argv[1] == "morning" :
# morning BLUE light hours
# BLUE light is stimulating
start_morning = "06:00:00"
end_morning = "10:00:00"
# evening RED light hours
# RED light is calming allows melatonin production to increase
start_night = "18:00:00"
end_night = "22:00:00"
color_change = False
while True:
date_string = datetime.datetime.now().strftime("%H:%M:%S" )
if date_string == start_morning:
color = (0, 0, 255)
elif sys.argv[1] == "night" :
color = (255, 0, 0)
elif sys.argv[1] == "day" :
color = (255, 255, 255)
elif sys.argv[1] == "off" :
color_change = True
elif date_string == end_morning:
color = (0, 0, 0)
color_change = True
pixels.fill(color)
elif date_string == start_night:
color = (255, 0, 0)
color_change = True
else:
print("valid arguments are morning, night or off")
elif date_string == end_night:
color = (0, 0, 0)
color_change = True
else:
time.sleep(1)
# update neopixel strip with new colors
if color_change:
pixels.fill(color)
color_change = False
time.sleep(1)