Code question with a line follow sensor...
June 8, 2008
So I am trying to add a encoder on one of my wheels so the robot knows how far it has gone/turned. I am using a simple IR line follower sensor and this on one of my gears:
The sensor can tell the diference between black and right obviously, and the sensor works well -I have had it blink a LED on and off and it worked great.
Now I am trying to get the picaxe to count the white spaces and am running into problems...
Here is the code I am using now:
servo 2,75 'make the servo motor go
if pin3=1 then let w1=1+1 'input pin for line follow sensor (high = white)
if w1=16 then goto onerev 'should be one full turn
high 6 'turn on indicator led
low 2 'stop drive motor
low 6 'turn off indicator led
Here's the problem:
As the code cycles round and round, it might count a "white or high" space a few times not just once. As the gear turns and the sensor reads white and black the code cycles around... The gear could be on a white space for 3 or 4 cycles of code and thus the code will keep adding 1 to the w1 variable 3 or 4 times. Does anyone have any ideas as to count a high signal as only a 1 count until that pin goes low?
Did that make sense?