Practice and reinforce the concepts from Lesson 8
Time needed: 30-35 minutes
Build your own countdown timer app with alarm sounds! You'll create buttons to set the time, start the countdown, and play an alarm when time's up. It's like having your own personal timer for games, homework, or cooking!
Please watch this video to see how this app works.
:white_check_mark: Open MIT App Inventor
:white_check_mark: Create a new project called "MyTimer"
:white_check_mark: Have your alarm sound file ready (or use the default sounds)
:white_check_mark: Review the Clock component from the lesson
Visible and non-visible components that you will be using to make the app:
Sample UI | Components |
---|---|
![]() |
Layouts: Vertical Arrangement Horizontal Arrangements Visible components: Buttons Labels TextBox Non-visible component: Clock Player |
Let's build your timer step by step! :rocket:
Create a global variable for timer, and set it as 0.
:bulb: This variable will store how many seconds are left in your countdown!
When the app is opened, disable the timer.
Why? We don't want the timer to start counting down right away!
When the Plus Button is clicked:
:bulb: Stuck?
Remember: You need to add 1 to the current timer value, not just set it to 1! Use the math block:
set global timer to (get global timer) + 1
When the Minus Button is clicked:
When the Start Button is clicked, enable the timer.
This makes the Clock component start ticking! :alarm_clock:
When the Stop Button is clicked:
When the timer is enabled (use the Clock.Timer event):
:bulb: Stuck?
To countdown, subtract 1 from the timer variable each time! For the alarm loop, check the Player component properties - there's a "Loop" checkbox!
When the Set Timer Button is clicked:
Ready to make your timer even better? Try these extra features:
Update your Step 4: The Minus Button should only work if the timer value is larger than 0.
Why? We don't want negative time! That would be weird! :emoji:
Update your Step 5: When the Start Button is clicked, the timer will only be enabled if the timer variable is more than 0.
This prevents starting an empty timer!
Create a new button: When Pause Button is clicked, just disable the timer (different from Stop Button, where the timer resets).
This lets you pause and resume your countdown!
Update your Step 8: When the Set Timer Button is clicked:
If the textbox is empty:
If the textbox is not empty:
:bulb: Stuck?
Use an if-then-else block to check if the textbox is empty first! Then inside the "else" part, check if the number is greater than 0.
Before submitting, make sure:
Great job building your timer app! You've learned how to use the Clock component and create a useful tool! :star2: