Datasheet

Page 60· Applied Robotics with the SumoBot
LedSpeaker PIN 5
After declaring this
PIN directive, the name LedSpeaker can be used as either an input or
an output. The BASIC Stamp Editor examines each command with
LedSpeaker as an
argument and decides whether to send an output to the pin or store the input value sensed
by the pin. When used in the
PIN argument of commands like HIGH, LOW, TOGGLE, or
FREQOUT, the BASIC Stamp Editor treats the I/O pin as an output.
Example Program: TestLedSpeaker.bs2
Enter, save, and run TestLedSpeaker.bs2.
Verify that it makes the LED rapidly turn on/off several times.
The piezospeaker should then play a brief tone.
If either of the components do not behave as expected, check your circuit and
program for errors.
Remember Each time the LED changes state, the speaker will make a clicking noise, and
each time the speaker plays, the LED will turn on.
If the LED doesn't turn on, remember from What's a Microcontroller and Robotics with the
Boe-Bot that the LED is a 1-way current valve. The LED's shorter cathode lead should be
connected to Vss; otherwise current will not flow through it.
' -----[ Title ]--------------------------------------------------------------
' Applied Robotics with the SumoBot - TestLedSpeaker.bs2
' Tests the LED and piezospeaker circuit connected to P5 by flashing
' the LED on/off 15 times, then playing a tone on the speaker.
' {$STAMP BS2} ' Target = BASIC Stamp 2
' {$PBASIC 2.5} ' Language = PBASIC 2.5
' -----[ I/O Definitions ]---------------------------------------------------
LedSpeaker PIN 5 ' LED/speaker connected to P5
' -----[ Variables ]----------------------------------------------------------
counter VAR Byte ' Loop counting variable
' -----[ Initialization ]-----------------------------------------------------
DEBUG CLS, "LED flashing..." ' Prompt to check LED
' -----[ Main Routine ]-------------------------------------------------------