-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpomodoroMain.py
More file actions
143 lines (104 loc) · 3.29 KB
/
pomodoroMain.py
File metadata and controls
143 lines (104 loc) · 3.29 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import time
from Adafruit_LED_Backpack import SevenSegment
import RPi.GPIO as GPIO
# Create display instance on default I2C address (0x70) and bus number.
display = SevenSegment.SevenSegment()
# Alternatively, create a display with a specific I2C address and/or bus.
# display = SevenSegment.SevenSegment(address=0x74, busnum=1)
# Initialize the display. Must be called once before using the display.
display.begin()
# Keep track of the colon being turned on or off.
colon = True
pomodoroMode = True
timerRunning = False
threeSecondCheck = 0
twentyFiveMinutes = 0
GPIO.setmode(GPIO.BCM)
GPIO.setup(17,GPIO.IN,pull_up_down=GPIO.PUD_UP)
# Yellow lights
GPIO.setup(16,GPIO.OUT)
# Buzzer buzzer
GPIO.setup(26,GPIO.OUT)
def setup():
print("in setup")
global twentyFiveMinutes
twentyFiveMinutes = 1500
# twentyFiveMinutes = 10
GPIO.output(16, GPIO.HIGH)
def checkForButton():
if (GPIO.input(17) == False):
return True
def sleepAndLookForClick():
clickCount = 0
for i in range(0,10):
if (checkForButton()):
clickCount += 1
# print ('button pushed ' + str(clickCount))
# else:
# count = 0
time.sleep(.1)
# print('sleep' + str(i))
return clickCount
def finishedPomodoro():
global pomodoroMode
pomodoroMode = False
for i in range(0,5):
GPIO.output(26, GPIO.HIGH)
GPIO.output(16, GPIO.HIGH)
display.clear()
display.write_display()
time.sleep(.4)
GPIO.output(26, GPIO.LOW)
GPIO.output(16, GPIO.LOW)
display.print_float(8888)
display.write_display()
time.sleep(.4)
global twentyFiveMinutes
twentyFiveMinutes = 300
# Run through different number printing examples.
print('Press Ctrl-C to quit.')
setup()
buttonWasPressed = False
while True:
m, s = divmod(twentyFiveMinutes, 60)
currentTime = float(m) + (s / 100.00)
# Clear the display buffer.
display.clear()
# Print a floating point number to the display.
display.print_float(currentTime)
# Set the colon on or off (True/False).
display.set_colon(colon)
# Write the display buffer to the hardware. This must be called to
# update the actual display LEDs.
display.write_display()
# Delay for a second.
# time.sleep(1)
resultOfClick = sleepAndLookForClick()
if (resultOfClick > 0):
if (buttonWasPressed == False):
timerRunning = not timerRunning
buttonWasPressed = True
else:
threeSecondCheck = 0
buttonWasPressed = False
if (resultOfClick > 0):
threeSecondCheck += resultOfClick
# print ("addtion of " + str(threeSecondCheck))
if (threeSecondCheck > 30):
# print("reset the timer")
timerRunning = False
setup()
if timerRunning:
twentyFiveMinutes -=1
if (pomodoroMode):
GPIO.output(16,GPIO.HIGH)
# else:
# GPIO.output(16,GPIO.LOW)
if (twentyFiveMinutes == 0) and (timerRunning) and (pomodoroMode):
finishedPomodoro()
elif (twentyFiveMinutes == 0) and (pomodoroMode == False) and (timerRunning):
setup()
pomodoroMode = True
timerRunning = False
# Print the same numbers with 1 digit precision.
GPIO.cleanup()