Datasheet

Chapter 2: EEPROM Tricks and Program Tips · Page 61
FOR counter = 1 TO 30 ' Flash LED on/off 15 times
TOGGLE LedSpeaker
PAUSE 250
NEXT
DEBUG CR, "Speaker playing tone" ' Prompt to listen for tone
FREQOUT LedSpeaker, 2000, 3000 ' Play 3 kHz tone for 2 seconds
DEBUG CR, "All done." ' Prompt user - program finished
END
Your Turn - Playing Musical Notes
The LOOKUP command can be handy for storing brief sequences of musical notes.
Save a copy of the program as TestLedSpeakerYourTurn.bs2.
Add the variable declaration
note VAR Word.
Replace the single
FREQOUT command in TestLedSpeaker.bs2 with this
FOR...NEXT loop.
FOR counter = 0 TO 7
LOOKUP counter, [1046, 1175, 1319,
1397, 1580, 1760,
1976, 2093], note
FREQOUT 5, 500, note
PAUSE 25
NEXT
Run the program and listen to the results.
Save the modified program.
Building and Testing the Pushbutton Circuit
Figure 2-5 shows the pushbutton circuit connected to P6. When the pushbutton is not
pressed, P6 senses ground through the 470 and 10 k resistors, and stores a 0 in its
IN6 input register. If the pushbutton is pressed, P6 senses the direct connection to Vdd,
and stores a 1 in
IN6.
Build the circuit shown in Figure 2-5.