'{$STAMP BS2} '*** Listing 3 of 4: LED on/off with switch + reading a photocell *** 'SPST switch: 'one side to +5V (VDD) 'other side to BS2 pin 1 (input) + 10K resistor (BR-BL-OR) '10K resistor to ground (VSS) 'LED: 'short pin (cathode) to ground (VSS) 'long pin (anode) to 220 ohm resistor (RED-RED-BR) '220 ohm resistor to BS2 pin 8 (output) 'PHOTOCELL (or potentiometer) '+5V (VDD) to capacitor (0.1uF, usually labeled 104) 'capacitor to photocell & 220 ohm resistor (RED-RED-BR) 'other side of photocell to ground (VSS) '220 ohm resistor to pin 10 switchPin var in1 'set variable to input pin 1 state switchPrev var bit 'bit for keeping track of previous pin state ledPin con 8 'output pin for LED potPin con 10 'input pin for photocell potResult var word 'photocell rcTime result potPrev var word 'previous photocell result start: debug "STAMP PROGRAM STARTING...",cr label1: pause 50 if switchPin <> switchPrev then switchChange label2: high potPin 'discharge capacitor pause 1 'for 1 ms rcTime potPin,1,potResult 'measure RC charge time if potResult <> potPrev then potChange goto label1 switchChange: if switchPin = 1 then switchOn switchPrev = switchPin debug "SWITCH: ",dec switchPin,cr goto offLED switchOn: switchPrev = switchPin debug "SWITCH: ",dec switchPin,cr goto onLED onLED: high ledPin debug "LED ON",cr goto label2 ' offLED: low ledPin debug "LED OFF",cr goto label2 potChange: potPrev = potResult debug ? potResult goto label1