Electronics Projects: How to Assign Names to I/O Pins in PBASIC Code

Programmable circuits in electronics projects require a bit of programming. If your programmable circuit is a BASIC Stamp, you’ll write that code in PBASIC. PBASIC lets you assign a name to an I/O pin. This feature makes the program a bit more self-documenting.

For example, you can use the HIGH and LOW statements to set the output status of an I/O pin. The following statement sets pin 6 to HIGH:

HIGH 6

Here, the number 6 indicates that pin 6 should be set to HIGH.

The problem with using just the pin number to identify which pin you want to control is that you can’t tell what kind of device is connected to pin 6 simply by looking at the statement. It could be an LED, but it could also be a motor or a servo or even a pneumatic valve that causes a Frankenstein creature to pop up.

To remedy this situation, PBASIC lets you assign a name to an I/O pin by placing a statement similar to this one near the beginning of your program:

Led1 PIN 0

Here, the name Led1 is assigned to pin 0. Now, you can use the name Led1 in a HIGH or LOW statement, like this:

HIGH Led1

This statement sets the I/O pin referenced by the name Led1 to HIGH.

Here is a program that uses pin names instead of the pin numbers. The real advantage of creating PIN names is that it makes it much easier to change the pin configuration of your project later on.

For example, suppose you decide that instead of connecting the six LEDs to pins 0, 2, 4, 6, 8, and 10, you want to connect them to pins 0, 1, 2, 3, 4, and 5. By using pin names, you must change the pin assignments just once when you modify the program, in the PIN statements near the beginning of the program.