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.
Connect the buzzer as shown in figure 1:
The long PIN is positive.
Write a sketch K to define:
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
Try the following commands now:
] beep
the buzzer emits 4 beeps (buz=!buz ^8 switches buz 8 times every tenth of a second)
] alarmOn
the buzzer emits 4 beeps every 3 seconds
] ??
--- Periodic commands
beep #3
shows the periodic commands running
] alarmOff
the buzzer does not emit any beeps
] ??
null
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: