/ Circadian_Pi_Desk_Light / Circadian_Pi_Desk_Light.py
Circadian_Pi_Desk_Light.py
 1  # SPDX-FileCopyrightText: 2019 Mikey Sklar for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  import datetime
 6  import time
 7  import board
 8  import neopixel
 9  
10  pi_pin = board.D18
11  numpix = 144
12  brightness = 1.0
13  pixels = neopixel.NeoPixel(pi_pin, numpix, brightness=brightness)
14  
15  # morning BLUE light hours
16  # BLUE light is stimulating
17  start_morning = "06:00:00"
18  end_morning = "10:00:00"
19  
20  # evening RED light hours
21  # RED light is calming allows melatonin production to increase
22  start_night = "18:00:00"
23  end_night = "22:00:00"
24  
25  color_change = False
26  
27  while True:
28      date_string = datetime.datetime.now().strftime("%H:%M:%S" )
29  
30      if date_string == start_morning:
31          color = (0, 0, 255)
32          color_change = True
33  
34      elif date_string == end_morning:
35          color = (0, 0, 0)
36          color_change = True
37  
38      elif date_string == start_night:
39          color = (255, 0, 0)
40          color_change = True
41  
42      elif date_string == end_night:
43          color = (0, 0, 0)
44          color_change = True
45  
46      else:
47          time.sleep(1)
48  
49      # update neopixel strip with new colors
50      if color_change:
51          pixels.fill(color)
52          color_change = False
53          time.sleep(1)