contolling a servo with a photoresitor
hotrod
Posts: 14
Hey, I am just starting in the code writing world. I am building a circuit that uses a photoresitor and servo. I am trying to write the code for the·basic stamp. What I want the program to do is move the servo to two position depending on how much light is being measured by the photoreistor. If anyone out there has any suggestion I would really appreciate your help. I am using a basic stamp 2 on the homework board.
Comments
Say your min digital was 10 and max was 25, and the timing for your BS meant that servo min and max were 800 and 1600. There is a diffrence in the digital of 15 and the servo of 800 so 800/15 = ehh, 50 is close enough
Then get the digital and put it into variable x
do
gosub getdigi
y=x*50
pulsout 0, 20, y
pause ??
loop
You get the idea. BTW, I totally pulled every one of those numbers out of my butt, just so you know, make sure you use valid ones.
You don't need an ADC if you use the RC time circuit described on page 189. Use that to read the photoresistor into a variable in your BS2. Then use the values of that variable to control the servo, using the kind of scaling that GICU812 described.