|
1 | 1 | # Pomodoro Timer prototype
|
| 2 | +# This is a prototype for a Pomodoro Timer circuit board |
2 | 3 |
|
3 | 4 | import time
|
4 |
| -import sys |
| 5 | +#import sys |
5 | 6 | from machine import Pin
|
6 | 7 |
|
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): |
12 | 10 | while time_sec:
|
13 | 11 | mins, secs = divmod(time_sec, 60)
|
14 | 12 | timeformat = '{:02d}:{:02d}'.format(mins, secs)
|
15 | 13 | #sys.stdout.write('\r' + timeformat + 's')
|
16 | 14 | print(timeformat)
|
17 | 15 | time.sleep(1)
|
18 | 16 | 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 |
19 | 28 |
|
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) |
21 | 48 |
|
22 | 49 | #Configuration
|
23 | 50 | pomodoroTimer = 25
|
24 |
| -breakTimer = 5 |
25 |
| -longBreak = breakTimer * 2 |
| 51 | +shortBreak = 5 |
| 52 | +longBreak = shortBreak * 2 |
| 53 | +longAfterPomodoros = 4 |
| 54 | +pomodoroCount = 0 |
26 | 55 |
|
27 | 56 | 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() |
39 | 78 |
|
40 | 79 |
|
0 commit comments