My Account: Log In

0 item(s) in cart/ total: $0.00 view cart

Basic Stamp 2 Workshop - EXAMPLES

Reprinted from original article by Vincent Leclerc

available here

 

MAIN Flashing LEDs with a switch Flashing LEDs with a potentiometer Theremin controlled by a photoresistor

 

Flashing LEDs with a switch

 

The curse

There's an old legend that tells the woeful tale of an electronics hobbyist who was experimenting with a new type of microcontroller. Once he understood the basics of the new device and its instruction set, he proceeded to write a terrific program that allowed the microcontroller to monitor the temperature of his personal computer processor...
After considering debugging, the program was ready to be entered into the microcontroller for a test run. The hobbyist burned the software into the device, plugged it into the hardware, and placed the temperature sensor in the proper place inside his computer. He then fired up the PC and sat back, admiring his new project. Everything was ready for a trial. With the flip of a switch, power was applied to the temperature sensor and, voilà, the microcontroller, with the dedicated temperature-sensing code, worked flawlessly! The LCD display came alive with the proper information, and each time the temperature changed, the display accurately indicated that change. Yes, it was a brillant effort!
The only problem seemed to be that at the instant the hobbyist activated the power switch, a dark and very dense cloud of smoke rose around the chair he was seated in. When the smoke finally cleared, he was nowhere to be found. All that was left was a few wisps from the original thick haze, rising from the chair. He had vanished - never to be seen again, alive or otherwise!
After an exhaustive, but inconclusive, investigation it was determined that the hobbyist had commited the unforgivable sin of not making his first project, regarding the new microcontroller, a light-emitting diode (LED) flasher. This unacceptable error resulted in his banishment to a as-yet-not-totally-understood place (probably floating in limbo for eternity). There was simply no other rational explanation. Other theories were proposed, but considering the legend of "the curse" associated with not flashing an LED first, these were rejected, and the case of this hobbyist's disappearance was closed forever.

Excerpt from "Guide to PICMICRO Microcontrollers", by Carl Bergquist

Schema of the circuit

Code

'{$STAMP BS2}

infiniteLoop: 'label

'if button is pressed, goto subroutine Flash
IF IN1 = 1 THEN Flash

GOTO infiniteLoop 'loop

 

Flash: 'subroutine labeled Flash

HIGH 0 'turn on LED
PAUSE 1000 'wait 1 second
LOW 0 'turn off LED
PAUSE 1000 'wait 1 second

RETURN 'go back to the rest of the program

 

 

Flashing LEDs with a potentiometer

 

Schema of the circuit

Code

'{$STAMP BS2}

'define a variable of size WORD
'name it speed
'it will be the speed at which
'we flash the LED
speed VAR WORD

infiniteLoop: 'label

HIGH 1 'discharge the capacitor
PAUSE 1 'for 1 milisecond

'check the time it takes to charge
'and put the value in the variable speed
RCTIME 1,1,speed

'display the value of speed on screen
DEBUG ? speed

'now flash the LED
GOSUB Flash

GOTO infiniteLoop 'loop

Flash: 'subroutine labeled Flash

HIGH 0 'turn on LED
PAUSE speed 'wait x second
LOW 0 'turn off LED
PAUSE speed 'wait x second

RETURN 'go back to the rest of the program

 

 

Theremin controlled by a photoresistor

 

Schema of the circuit

Code

'{$STAMP BS2}

' Variables
tone VAR Word ' frequency output

' Program Code
Main:
HIGH 0 ' discharge cap
PAUSE 1 ' for 1 ms
RCTIME 0, 1, tone ' read the light sensor

tone = tone - 1000 ' adjust the value
FREQOUT 5, 100, tone ' output the tone for 1/10 of a second
GOTO Main