LED Light detector
Hi everyone, I am just getting back in to playing with SX/B (its been a few years.) I was playing around with making an LED light detector. So i have an led hooked between RB.1 and RB.2 with a resistor in series. Here is the code:
I have another LED connected to RB.7 that is supposed to turn on if the value of light is 0. Not seeming to work. I copied this from similar code i found from the basic stamp and it worked fine with my stamp. I just made a few changes for the SX and no go...
Here is the code i used as a base for the Stamp:
Thanks!
John G
'PWM.SXB
DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ 4_000_000
led2 PIN RB.2
led1 PIN RB.1
led7 PIN RB.7
light VAR Word
time CON 2000
'Code
PROGRAM Start
Start:
led1 = 1
led2 = 0
DO
OUTPUT led2
OUTPUT led1
RCTIME led1, 1, light
IF light = 0 THEN
led7 = 1
ELSE
led7 = 0
ENDIF
PAUSE time
LOOP
I have another LED connected to RB.7 that is supposed to turn on if the value of light is 0. Not seeming to work. I copied this from similar code i found from the basic stamp and it worked fine with my stamp. I just made a few changes for the SX and no go...
Here is the code i used as a base for the Stamp:
'{$PBASIC 2.5}
'file:LED_Emitter_Detecter.bs2
'Clark Radcliffe
'Michigan State University
'July 30, 2007
'Requires an LED in series with a 220 Ohm resister
'between pin 1 and the LED connected to pin 2
'Declarations
Pin2 PIN 2
Pin1 PIN 1
light VAR Word
time CON 2000
'Code
DEBUG "Start test...", CR
DO
DEBUG "LED is a detecter (LED off and charging)", CR
Pin1 = 1
Pin2 = 0
PAUSE 10
RCTIME pin1, 1, light
DEBUG "Light measured = ", DEC light, CR
PAUSE time
LOOP
Thanks!
John G

Comments
I don't see in your code where RB.7 is set as an output. It could be that the pin is set as an input.
-Benoit
Your Stamp code debugs out the value; for the SX, use WATCH and then run the program in DEBUG mode with your Key connected. Then try it out and see what values you get for various light intensities -- once you have a decent threshold number established, then you can have an LED turn on and off based on that threshold.
Then, shouldn't the loop turn the led back on (and maybe pause) to charge up the capacitance again?
'PWM.SXB DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX FREQ 4_000_000 led2 PIN RB.2 OUTPUT led1 PIN RB.1 OUTPUT led7 PIN RB.7 OUTPUT light VAR Word time CON 2000 someThreshold CON 100 ' or whatever a good number ends up being WATCH light 'Code PROGRAM Start Start: DO 'OUTPUT led2 'OUTPUT led1 'led1 = 1 'led2 = 0 HIGH led1 ' makes high and output LOW led2 PAUSE time RCTIME led1, 1, light ' also automatically makes led1 an input IF light < SomeThreshold THEN led7 = 1 ELSE led7 = 0 ENDIF LOOP▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
When the going gets weird, the weird turn pro. -- HST
1uffakind.com/robots/povBitMapBuilder.php
1uffakind.com/robots/resistorLadder.php
Post Edited (Zoot) : 7/2/2009 1:26:56 AM GMT
That was it. Thanks! It works perfectly now.
John Gjonola