You are on page 1of 3

Programs that Control the LED Test Circuits

The HIGH and LOW commands can be used to make the BASIC Stamp connect an LED alternately to Vdd and Vss. The Pin argument is a number between 0 and 15 that tells the BASIC Stamp which I/O pin to connect to Vdd or Vss.
HIGH Pin LOW Pin

For example, if you use the command:


HIGH 13

...it tells the BASIC Stamp to connect I/O pin P13 to Vdd, which turns the LED on. Likewise, if you use the command
LOW 13

...it tells the BASIC Stamp to connect I/O pin P13 to Vss, which turns the LED off. Lets try this out.
Example Program: HighLowLed.bs2

Reconnect power to your board. Enter, save, and run HighLowLed.bs2. Verify that the LED circuit connected to P13 is turning on and off, once every second.
' Robotics with the Boe-Bot HighLowLed.bs2 ' Turn the LED connected to P13 on/off once every second. ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "The LED connected to Pin 13 is blinking!" DO HIGH 13 PAUSE 500 LOW 13 PAUSE 500 LOOP Your Boe-Bots Servo Motors Page 33

How HighLowLed.bs2 Works

Figure 2-6 shows how the BASIC Stamp can connect an LED circuit alternately to Vdd and Vss. When its connected to Vdd, the LED emits light. When its connected to Vss, the LED does not emit light. The command HIGH 13 instructs the BASIC Stamp to connect P13 to Vdd. The command PAUSE 500 instructs the BASIC Stamp to leave the circuit in that state for 500 ms. The command LOW 13 instructs the BASIC Stamp to connect the LED to Vss. Again, the command PAUSE 500 instructs the BASIC Stamp to leave it in that state for another 500 ms. Since these commands are placed between DO and LOOP, they execute over and over again.
SOUT SIN ATN VSS P0 P1 P2 P3 P4 P5 P6 P7 VIN VSS RES VDD (+5V) P15 P14 P13 P12 P11 P10 P9 P8
24 23 22 21 20 19 18 17 16 15 14 13 1 2 3 4 5 6 7 8 9 10 11 12

BS2-IC BS2
Vdd Vss
SOUT SIN ATN VSS P0 P1 P2 P3 P4 P5

P6 P7 VIN VSS RES VDD (+5V) P15 P14 P13 P12 P11 P10 P9 P8
24 23 22 21 20 19 18 17 16 15 14 13 1 2 3 4 5 6 7 8 9 10 11 12

BS2-IC BS2
Vdd Vss

Figure 2-6 BASIC Stamp Switching The BASIC Stamp can be programmed to internally connect the LED circuits input to Vdd or Vss.

A Diagnostic Test for your Computer

A very few computers, such as some laptops, will halt the PBASIC program after the first time through a DO...LOOP instruction. These computers have a non-standard serial port design. By placing a DEBUG command the program LedOnOff.bs2, the open Debug Terminal prevents this from possibly happening. You will next re-run this program without the DEBUG command to see if your computer has this non-standard serial port problem. It is not likely, but it would be important for you to know. Open HighLowLed.bs2. Delete the entire DEBUG instruction. Run the modified program while you observe your LED. If the LED blinks on and off continuously, just as it did when you ran the original program with the DEBUG command, your computer will not have this problem.
Page 34 Robotics with the Boe-Bot

If the LED blinked on and off only once and then stopped, you have a computer with a non-standard serial port design. If you disconnect the programming cable from your board and press the Reset button, the BASIC Stamp will run the program properly without freezing. In programs you write yourself, you should add a single command:
DEBUG "Program Running!"

...right after the compiler directives. This will open the Debug Terminal and keep the COM port open. This will prevent your programs from freezing after one pass through the DOLOOP, or any of the other looping commands you will be learning in later chapters. You will see this command in some of the example programs that would not otherwise need a DEBUG instruction. So, you should be able to run all of the remaining programs in this book even if your computer failed the diagnostic test.
Introducing the Timing Diagram

A timing diagram is a graph that relates high (Vdd) and low (Vss) signals to time. In Figure 2-7, time increases from left to right, and high and low signals align with either Vdd (5 V) or Vss (0 V). This timing diagram shows you a 1000 ms slice of the high/low signal you just experimented with. The line of dots (. . .) to the right of the signal is one way of indicating that the signal repeats itself.
Vdd (5 V) Vss (0 V) 500 ms 1000 ms

500 ms

Figure 2-7 Timing Diagram for

HighLowLed.bs2 The LED on/off states are shown above the timing diagram.
Your Boe-Bots Servo Motors Page 35

Your Turn Blink the Other LED

Blinking the other LED (connected to P12) is a simple matter of changing the Pin argument in the HIGH and LOW commands and re-running the program. Modify the program so that the commands look like this:
DO HIGH 12 PAUSE 500 LOW 12 PAUSE 500 LOOP

Run the modified program and verify that it makes the other LED blink on/off. You can also make both LEDs blink at the same time. Modify the program so that the commands look like this:
DO HIGH 12 HIGH 13 PAUSE 500 LOW 12 LOW 13 PAUSE 500 LOOP

Run the modified program and verify that it makes both LEDs blink on and off at roughly the same time. You can modify the program again to make one LEDs blink alternately on/off, and you can also change the rates that the LEDs blink by adjusting the PAUSE commands Duration argument higher or lower.

You might also like