-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalarmclock.py
90 lines (63 loc) · 2.52 KB
/
alarmclock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
__author__ = 'josephelliott'
import time
import datetime
from piglow import PiGlow
from pytz import timezone
def wakeSequence(wakeSeconds, seconds):
#begin the wake sequence
#start with just the orange LEDs
orangeStart = 0
orangeRampDuration = wakeSeconds
orangeRamp = 255.0/orangeRampDuration #power per second
#The then yellow at 10 min
yellowStart = (wakeSeconds*(1/3.0))
yellowRampDuration = wakeSeconds - yellowStart
yellowRamp = 255.0/yellowRampDuration
#then the white at 5 min
whiteStart = (wakeSeconds*(2/3.0))
whiteRampDuration = wakeSeconds - whiteStart
whiteRamp = 255.0/whiteRampDuration
if seconds >= orangeStart:
orangeBrightness = int(orangeRamp*(seconds - (wakeSeconds - orangeRampDuration)))
print("Orange brightness at %i" % orangeBrightness)
if orangeBrightness <= 255:
piglow.orange(orangeBrightness)
if seconds >= yellowStart:
yellowBrightness = int(yellowRamp*(seconds - (wakeSeconds - yellowRampDuration)))
print("Yellow brightness at %i" % yellowBrightness)
if yellowBrightness <= 255:
piglow.yellow(yellowBrightness)
if seconds >= whiteStart:
whiteBrightness = int(whiteRamp*(seconds - (wakeSeconds - whiteRampDuration)))
print("White brightness at %i" % whiteBrightness)
if whiteBrightness <= 255:
piglow.white(whiteBrightness)
#Run the script
piglow = PiGlow()
hours = 5
minutes = 45
timezone = timezone('US/Eastern')
#Takes 15 minutes to fully wake up
wakeDuration = datetime.timedelta(minutes=15)
#shut off after 10 min at full power
totalDuration = wakeDuration + datetime.timedelta(minutes=10)
try:
while True:
#set the wake time then enter the loop
currentTime = datetime.datetime.now(timezone)
wakeTime = currentTime.replace(hour=hours, minute=minutes, second=0)
shutOffTime = wakeTime + totalDuration
weekend = wakeTime.weekday() > 5 #Monday=0, Sunday=6.
if wakeTime < currentTime < shutOffTime and (not weekend):
seconds = currentTime - wakeTime
print("Wake sequence at %i seconds" % seconds.seconds)
wakeSequence(wakeDuration.seconds, seconds.seconds)
else:
#shut off after 10 min at full power
print("Sleeping...zzzzz")
piglow.all(0)
# sleep for a bit, don't go too fast!
time.sleep(1)
except KeyboardInterrupt:
# set all the LEDs to "off" when Ctrl+C is pressed before exiting
piglow.all(0)