02. Alarm clock
This example of digital output uses a buzzer to generate the alarm sound of a clock. It can be managed from the Internet via alarmOn and alarmOff commands.
Figure 1 - alarm clock 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: buz::d2
- the commands to control the buzzer: beep, alarmOn, alarmOff
buz :: d2
beep = [buz=!buz ^8]
alarmOn = [beep #3]
alarmOff = [beep #0, buz=0]
or simply load the sketch with the command
] load e02_buzzer
3. Try and learn
Try the following commands now:
the buzzer emits 4 beeps (buz=!buz ^8 switches buz 8 times every tenth of a second)
the buzzer emits 4 beeps every 3 seconds
--- Periodic commands
shows the periodic commands running
the buzzer does not emit any beeps
the periodic command beep #3 was deleted
] alarmOn ##30
sets a 30-second timer (wait for 30 seconds to hear the alarm).
In this lesson you learned or repeated:
- how to use a buzzer
- the commands: load, ??