Learning Outcome
In this chapter, we learn to
use input buttons to interact with Thonny’s console.
use piezo buzzer to produce sound.
create and use variables.
use while loop.
Introduction: Button and Buzzer
Activities: Build a water drinking reminder (Hydration Companion)
Challenge: Program drinking reminder to accept user input for duration.
Introduction to Button
Buttons are essential electronic components in modern technology that allow us to input commands and interact with various devices. They come in all shapes and sizes, from the tiny buttons on your calculator to the larger ones on your computer keyboard.
> Libraries <
-> Libraries: board, time, digitalio.
-> Button Configuration: Button A (Yellow) to GP0 as digital input.
< Expected Output >
Upon completion of the activity, you should be able to:
Press Button A and output "Button A is pressed" will be displayed at the shell console
Introduction to Buzzer
Want to make some noise with your EDU PICO? In this section, you will learn how to activate your EDU PICO built-in piezo buzzer. While you're at it, go ahead and hook up the EDU PICO to a headset or a speaker at the buzzer module too!
> Libraries <
-> Libraries: board, simpleio.
-> Audio / Buzzer Configuration: Buzzer to GP21.
-> Action Required: Flip the buzzer module switch downwards to enable buzzer output.
< Expected Output >
Upon completion of the activity, you should be able to:
Execute the code and EDU PICO buzzer module will continuously beep at a 2 seconds interval with a frequency of 440Hz
Water Drinking Reminder
Hydration Companion
Let's build a water drinking reminder with EDU PICO! Don't worry, we will keep your first project simple. Ultimately, you will learn how to combine codes from multiple components. Let's Go!
> Libraries <
-> Libraries: board, digitalio, time, simpleio.
-> Button Configuration: Button A (Yellow) = GP0, Button B (Blue) = GP1.
-> Input:
Press Button A to activate the 5 second (default) countdown.
Press Button B to reset the buzzer.
< Expected Output >
Upon completion of the activity, you should be able to:
Execute the code and the buzzer will start beeping once the countdown reaches zero
The program will print the reminder text and timer status to the user at the shell console
Challenges
#1 - Water Drinking Reminder
In the original code, the timer runs for only 5 seconds by default. In this challenge, you are required to modify the code to allow the user to customize the duration of the water-drinking reminder.
> Libraries <
-> Libraries: board, digitalio, time, simpleio.
-> Button Configuration: Button A (Yellow) = GP0, Button B (Blue) = GP1.
< Expected Output >
Upon completion of the activity, you should be able to:
Execute the program and manually set the reminder duration
The buzzer will start beeping once the countdown reaches zero
The program will print the reminder text and timer status to the user at the shell console
Complete! Well done on finishing Chapter 2! Keep the momentum going!