3.5 Adding a buzzer
Now lets look at how the buzzer works. We will use the
sound
command to control the buzzer.
1. Connect the buzzer module to P2.
2. Now lets write a program that plays two different “tunes”
depending on whether the slide switch is at 0 or 1. The flow
diagram will look like this:
3. To program the buzzer, we will use the
sound
command. Let’s have a look at how the
sound
command works. The
sound
command takes the general form:
SOUND
pin,( note1\duration1, note2\duration2 ……noteX\durationX )
pin
: this is the pin number that the buzzer is connected to (i.e. P2)
note
: is a number between 1 and 127 that specifies the frequency of the note.
duration
: this is a value between 1 and 65535 telling the buzzer how long to stay on the given
note for.
You can put together a series of notes to make a tune by specifying note length and note
frequency.
4.
Start the
Programming Editor
or
AXEpad
, or start a
new program by using the
File/New/Basic Program menu option.
Start
Is the
switch
1?
While the switch is
on 1, play tune 1
If the switch is
changed to 0
While the switch is
0, play tune 2
Yes
No
Содержание Versabot
Страница 1: ...The Versabot Manual July 2009...
Страница 23: ...Step 03 Step 04 Step 05...
Страница 24: ...Step 06 Step 07 Step 08...
Страница 25: ...Step 09 Step 10 Step 11...
Страница 26: ...Step 12 Step 13...