Chapter 3

More PBASIC Programming Tricks

IN THIS CHAPTER

check Reading the status of push buttons

check Using a potentiometer as input

check Generating random numbers

check Creating subroutines with the GOSUB command

In this chapter, you learn some additional PBASIC programming techniques that will become invaluable in your BASIC Stamp projects. Specifically, you learn how to handle input data in the form of push buttons, how to generate random numbers that will make your programs more interesting by adding a degree of randomness, how to read the value of a potentiometer, and how to organize your program into subroutines using the GOSUB command.

Using a Push Button with a BASIC Stamp

In Chapter 2 of this minibook, you learn how to connect an LED to a BASIC Stamp I/O pin and turn the LED on or off by using the HIGH and LOW commands in a PBASIC program. Those commands are designed to use BASIC Stamp I/O pins as output pins by setting the status of an I/O pin to HIGH or LOW so that external circuitry (such as an LED) can react to the pin’s status.

But what if you want to use an I/O pin as an input instead ...

Get Electronics All-in-One For Dummies, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.