Electronics Projects: Charging and Discharging a Capacitor
Electronics Projects: How to Limit Current with a Resistor
Electronics Projects: How to Program a Servo in PBASIC

Electronics Projects: How to Flash Multiple LEDs with a BASIC Stamp

This electronics project begins by connecting 6 LEDs to the breadboard in a BASIC Stamp HomeWork board and then continues by showing the programming necessary to flash all of the LEDs on and off. You can play with the programming to create different flash patterns.

Connect the LEDs

This project shows how you can build a test circuit that has six LEDs connected to pins 0, 2, 4, 6, 8, and 10 using components that come with the BASIC Stamp Activity Kit, which is available from most RadioShack stores. Note: You can also easily assemble this circuit with a Board of Education and your own LEDs and resistors.

image0.jpg image1.jpg image2.jpg

Flash the LEDs

Keep in mind that if you can turn an LED on or off with a PBASIC program, you can control anything that can be connected to a BASIC Stamp I/O port.

Here is a simple program that flashes all six of the LEDs on and off at half-second intervals. This program uses nothing more than the HIGH, LOW, PAUSE, and GOTO statements. The program turns all six LEDs on, pauses 500 ms (half a second), turns the LEDs off, waits another half second, and then jumps back to the Main label to start the whole process over.

' {$PBASIC 2.5}
' {$PBASIC 2.5}
 HIGH 10
 PAUSE 500
 LOW 0
 LOW 2
 LOW 4
 LOW 6
 LOW 8
 LOW 10
 PAUSE 500
 GOTO Main

The following paragraphs summarize the operation of this program:

  • ' {$PBASIC 2.5} – This line indicates that the program is written in version 2.5 of PBASIC. Every program you write for the BASIC Stamp 2 should include this line. You can insert it automatically into a program by choosing Directive→PBASIC→Version 2.5 or by clicking the PBASIC Version: 2.5 button in the toolbar.

  • *' {$PBASIC 2.5} – This line indicates that the program will run on a BASIC Stamp 2, and it's required for every program you run on a BASIC Stamp 2 microcontroller. You can insert it automatically by choosing Directive→Stamp→BS2.

  • *Main: – The label Main: identifies the location that the GOTO statement in line 19 jumps to. Main is known as a label, which is simply a named location in your program. To create a label, you just type a name followed by a colon. For more information about creating value names in PBASIC.

  • *HIGH 0 – This line sets the output of pin 0 to HIGH, which in turn lights up the LED. The following lines (6 through 10) similarly turn on pins 2, 4, 6, 8, and 10.

  • *PAUSE 500 – This line pauses the program for 500 ms (one-half of a second).

  • *LOW 0 – This line and the five that follow set the outputs of pins 0, 2, 4, 6, 8, and 10 to LOW, which in turn extinguishes the LEDs.

  • *PAUSE 500 – This line pauses the program for an additional half second.

  • *GOTO Main – This line transfers control of the program back to the Main label in line 4 so that the program will repeat.

  • Add a Comment
  • Print
  • Share
blog comments powered by Disqus
Electronics Projects: How to Flash an LED with a BASIC Stamp
Electronics Projects: How to Connect a Push Button to a BASIC Stamp
The Process of Building an Electronic Project
Control Your Electronics through a Parallel Port
Electronics Projects: How to Create a Transistor NOR Gate Circuit

Inside Dummies.com