Skip to content

Commit 8d80f65

Browse files
committed
Updated main.py with a working prototype of the timer
This working prototype is currently running in the RP2040 chip. The 'leave loop' question should be replaced with a conditional checking for the state of a pushbutton switch. The configuration of the Pomodoro will allow to change the duration of Pomodoros, breaks, and condition for long break.
1 parent d456896 commit 8d80f65

File tree

1 file changed

+59
-20
lines changed

1 file changed

+59
-20
lines changed

main.py

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,79 @@
11
# Pomodoro Timer prototype
2+
# This is a prototype for a Pomodoro Timer circuit board
23

34
import time
4-
import sys
5+
#import sys
56
from machine import Pin
67

7-
# This is a prototype for a Pomodoro Timer circuit
8-
led = Pin(6, Pin.OUT)
9-
10-
#functions
11-
def timer(time_sec):
8+
#Functions
9+
def Timer(time_sec):
1210
while time_sec:
1311
mins, secs = divmod(time_sec, 60)
1412
timeformat = '{:02d}:{:02d}'.format(mins, secs)
1513
#sys.stdout.write('\r' + timeformat + 's')
1614
print(timeformat)
1715
time.sleep(1)
1816
time_sec -= 1
17+
#TO-DO check for button state to pause/reset
18+
stopp = input('leave loop?')
19+
if stopp == 'yes':
20+
raise RestartExecution
21+
print("timer stop")#sound the buzzer
22+
23+
def Pomodoro():
24+
print('Pomodoro Start')
25+
print(f'Focus for {pomodoroTimer} minutes')
26+
led.on()
27+
Timer(pomodoroTimer)#*60 for debug
1928

20-
print("stop")
29+
def Breaks(count):
30+
if count == 4:
31+
msg = 'Long break Started'
32+
minutes = longBreak
33+
else:
34+
msg = 'Break Started'
35+
minutes = shortBreak
36+
print(msg)
37+
print(f'Unwind yourself for {minutes} minutes')
38+
led.off()
39+
Timer(minutes)#*60 for debug
40+
pomodoroCount = 0
41+
42+
#Classes
43+
class RestartExecution(RuntimeError):
44+
pass
45+
46+
#IO Configuration
47+
led = Pin(6, Pin.OUT)
2148

2249
#Configuration
2350
pomodoroTimer = 25
24-
breakTimer = 5
25-
longBreak = breakTimer * 2
51+
shortBreak = 5
52+
longBreak = shortBreak * 2
53+
longAfterPomodoros = 4
54+
pomodoroCount = 0
2655

2756
while (True):
28-
pomodoroCount = 0
29-
startTimer = input('start timer? y/n')
30-
if (startTimer.lower() == 'y'):
31-
print('pomodoro timer started')
32-
led.on()
33-
timer(pomodoroTimer)#*60
34-
pomodoroCount+=1
35-
timer(breakTimer)#*60
36-
else:
37-
print('pomodoro timer not started')
38-
led.off()
57+
selection = input('start timer: 1 auto | 2 manual | 3 config')
58+
if selection == '1':
59+
while(True):
60+
try:
61+
Pomodoro()
62+
pomodoroCount+=1
63+
Breaks(pomodoroCount)
64+
except RestartExecution:
65+
break
66+
if selection == '2':
67+
while(True):
68+
try:
69+
input('Press enter to start Pomodoro')
70+
Pomodoro()
71+
input('Press enter to start break')
72+
Breaks(pomodoroCount)
73+
except RestartExecution:
74+
break
75+
else:
76+
print('pomodoro timer configuration not available')
77+
led.off()
3978

4079

0 commit comments

Comments
 (0)