The Parallax BASIC Stamp is a classic microcontroller programmed in a beginner-friendly variant of the BASIC language called PBASIC. Code is written in the BASIC Stamp Windows Editor, which features specialized buttons to automatically insert mandatory compiler directives. Core Syntax Directives
Every program written for the BASIC Stamp 2 (BS2) must start with these two directive lines to define the target hardware chip and language version: ’ {\(STAMP BS2} ' {\)PBASIC 2.5} Use code with caution.
Note: The single quote (‘) denotes a comment, but the compiler actively reads the brackets inside to configure itself. 1. Hello World (The Debug Window)
This baseline program sends text back to your computer screen using the built-in Parallax Debug Terminal.
’ {\(STAMP BS2} ' {\)PBASIC 2.5} DEBUG “Hello, it’s me, your BASIC Stamp!” END Use code with caution. DEBUG: Command to print data on your PC monitor.
END: Puts the microcontroller into a low-power sleep state until reset. 2. Blinking an LED (Infinite Loop)
The “Hello World” of physical hardware involves toggling a pin to make an electronic component flash continuously.
’ {\(STAMP BS2} ' {\)PBASIC 2.5} DO HIGH 15 ‘ Turn on LED attached to Pin 15 PAUSE 1000 ’ Wait for 1000 milliseconds (1 second) LOW 15 ‘ Turn off LED on Pin 15 PAUSE 1000 ’ Wait for 1 second LOOP Use code with caution.
DO…LOOP: Creates an infinite loop that repeats the code blocks forever.
HIGH / LOW: Drives the specified I/O pin to 5 volts (on) or 0 volts (ground/off).
PAUSE: Freezes program execution for a designated duration in milliseconds. 3. Reading a Pushbutton (Conditional Logic)
This sample code monitors an input pin to see if a button has been pressed, changing hardware behavior based on user input. BASIC Stamp 2px micro processor? – Arduino Forum
Leave a Reply