09. Wake up
This example of analog output uses a buzzer to generate the sound of the police siren, the morning alarm and a timer. The circuit can be managed from the Internet via alarm, stop, timer and snooze commands.
Figure 1 - wake up circuit
Connect the buzzer as shown in figure 1:
- positive PIN to the PIN d2
- negative PIN to the PIN GND.
The long PIN is positive.
Write a sketch K to define:
- the output connection: sound::d2
- the commands to control the buzzer: beep, alarm, snooze, stop and timer
sound :: d2
beep = [sound=6,sound=0 ##1]
alarm = [beep #2]
snooze = [beep #0,alarm ##5]
stop = [sound=0]
timer = [alarm ##10]
or simply load the sketch with the command
] load e09_wake_up
Figure 2 - alarm clock and timer commands
3. Try and learn
Using the sound command we will create the sound of the police siren, the morning alarm and a timer.
Try the following commands now:
the buzzer emits an infinite sequence of beeps
the buzzer sounds the note LA
the buzzer sounds the note FA
] police = [sound=440 #2,sound=699 #2 ##1]
to create the sound of the police siren
to turn off the sound
generates a beep burst for a second
generates the alarm clock to wake you up every morning
to continue sleeping for another 5 seconds
to turn off the alarm
sets a 10-second timer (wait for 10 seconds to hear the alarm)
to turn off the timer.
In this lesson you learned or repeated:
- how to use a buzzer
- the commands: load, sound, #, ##