A timer
Build a 25-minute focus timer that counts down every second and plays a sound at the end.
What you'll build: a focus timer, like the Pomodoro app. It shows 25:00, counts down each second after you tap Start, pauses and resumes, and plays a sound when it reaches 0:00.
What you'll learn:
- Run steps every second with Start Timer, and end them with Stop Timer.
- Write seconds as minutes:seconds with a formula.
- Use one button for two jobs with an If.
- Share the end-of-session steps through a reusable action.
#The variables
| Name | Type | Starting value |
|---|---|---|
secondsLeft | Whole Number | 1500 (25 minutes) |
running | True / False | Off |
sessions | Whole Number | 0 |
soundOn | True / False | On |
Make them in Data & Logic with Add variable. Each is named after its type, so tap each name and type the one from the table.
#Steps
#Show the time
Add a Text. Next to its Content, tap ⚡︎ → Formula… and type:
(secondsLeft < 600 ? '0' : '') + fixed(floor(secondsLeft / 60), 0) + ':' + (secondsLeft % 60 < 10 ? '0' : '') + fixed(secondsLeft % 60, 0)- Give it a big Font, and add the Even-Width Numbers modifier so the digits don't jump around as they change.
Add a second Text for the status. Next to Content, tap ⚡︎ → Formula… and type:
running ? 'Focusing' : (secondsLeft < 1500 ? 'Paused' : 'Ready')
The canvas shows 25:00 and Ready.
#Finish a session
These steps run when the time runs out. They're a reusable action so the timer can run them.
- In Data & Logic, under Reusable actions, tap New action. Add these steps in the sheet that opens:
| Step | Settings |
|---|---|
| Stop Timer | Id focus |
| Set Value | State running, To off |
| Set Value | State sessions, To ⚡︎ → Formula… sessions + 1 |
| If | Condition soundOn. Under Then: Play Sound, Sound Alarm. |
| Play Haptic | Style Success |
| Show Message | Text Session done. Take a 5-minute break., Style Success, Seconds 5 |
| Reset Value | State secondsLeft |
- Tap Done, then tap the action's name,
newAction, and change it tofinishSession.
#Start and pause
Add a Button. Set its Title to:
{running ? 'Pause' : (secondsLeft < 1500 ? 'Resume' : 'Start')}- In its Actions tab, tap Add action → If and set Condition to
running. - Under Then (the timer is running, so pause it), add:
- Stop Timer, Id
focus. - Set Value, State
running, To off.
- Stop Timer, Id
- Under Else (it isn't running, so start it), add:
- Set Value, State
running, To on. - Start Timer, Id
focus, Every 1. Under its Do, add:- Set Value, State
secondsLeft, To ⚡︎ → Formula…max(secondsLeft - 1, 0). - If, Condition
secondsLeft == 0. Under Then: Run Action, ActionfinishSession.
- Set Value, State
- Set Value, State
#Reset and sound
- Add a second Button titled
Reset, with these steps: Stop Timer (Idfocus), Set Value (running, off), Reset Value (secondsLeft). - Add a Switch. Set its Title to
Play sound at the endand its Is On tosoundOn. - Optional: add a Text with
{sessions} sessions done.
Tap Preview and Start. To try the end without waiting 25 minutes, set secondsLeft's starting value to 5 for a moment.
#How it works
- Start Timer waits Every seconds, runs its Do steps, and repeats until a Stop Timer with the same Id ends it. The first run comes one second after the tap. Starting a timer whose Id is already running replaces it.
- Each second,
secondsLeftdrops by one;max(…, 0)keeps it from going below zero. When it reaches 0, the If runsfinishSession, which stops the timer, counts the session and plays the sound ifsoundOnis on. - Reset Value puts
secondsLeftback to its starting value, 1500. - The time formula:
floor(secondsLeft / 60)is the whole minutes andsecondsLeft % 60the seconds left over.fixed(…, 0)writes each without decimals, and the two? '0' : ''parts add a leading zero, so 65 seconds reads 01:05. - One button, two jobs: the If looks at
running, so the same tap pauses a running timer and starts a stopped one. The title uses the same idea.