Hi All,
Hoping someone can help with what seems like a simple problem!! I am hoping to use 2 slotted opto switch modules of the cheap Chinese type (See pictures). To help me control my robots turning, if I use a delay the turning angle varies with battery level, fully battery over 90 degs, flat batts 45ish deg. So I got a couple of those cheapy motors with 20 slot so called encloders, but it's just a slotted disk.
My code compiles, but does not work! and I can't see why! it does'nt seem to matter if I say A==1 or A==0 as it should work both ways (I think), its like the fuction AddIt never gets called. I did try using do-while but I just count'ent get that to compile.
Here's a couple of pics to show what I'm doing, hope you can point me in the right direction.
Regards
Mel.
/*
********************************
Filename: WheelCounter
Date: 04/09/2014
File Version:
Written by: Mel Saunders
Function: Count wheel pulses
Last Revision:
Target
********************************
MS 11/08/2014
*/
int led=13,in1=1,in2=2,Count,A;
void setup()
{
// initialize the digital pins.
pinMode(led,OUTPUT);
Serial.begin(9600);
digitalWrite(led,LOW);
Count=0;
}
void loop()
{
while(Count<30);
{
A=digitalRead(in2);
if(A==1)
{
AddIt();
}
}
}
void AddIt()
{
++Count;
Serial.print(" ");
Serial.print(Count);
Serial.print(" ");
digitalWrite(led,HIGH);
delay(10);
digitalWrite(led,LOW);
}