Using slotted optos to count wheel revs....

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);
}

Here's how I wrote some code just this weekend to determine the speed of a motor. I have a slotted disk thing too, not quite like that, but I cut it to bits so that there is only 1 pulse per rev for testing. That way the pulse starts are far enough apart for me to see exactly what's going on.

That said, I have a pulse per rev variable in there anyway, currently set to 1.

The below function is called once per pass through loop().

void calcMotorSpeedActual()
{
  sensorState=digitalRead(sensorPin);
  //Serial.println(sensorState);
    if ((sensorState != lastSensorState) && sensorState == HIGH) //changed and HIGH means just got interrupted
  {
      nowMillis=millis();
      pulseTime= nowMillis - prevMillis;
      motorSpeedActual= 60000 / pulsesPerRev  / pulseTime;
      Serial.print(pulseTime);
      Serial.print(" ");
      Serial.println(motorSpeedActual);
      prevMillis = nowMillis;
  }
  lastSensorState = sensorState;
} //end of  calcMotorSpeedActual

RPM from there agrees with my own count with a stopwatch.

Hi All,
@Jimbo thanks for your reply. I tried your code in my function, but I still get nothing showing in ther serial monitor!! So I have to ask is my first bit of coding OK, like having a IF inside a while loop like this:

	while(Count<30);
	{
		A=digitalRead(in2);
		if(A==1)
		{
		AddIt(); //call a function to inc(++) Count var, and flash LED
		}
		
	}

or I did try a do-while loop but neither seem to work, it's got to be so simple that even I can't see it!!

Regards

Mel.