I have some trouble with the following if() loop (its only part of the whole thing):
int ldr1 = A0; // right ldr
int ldr2 = A1; // centre ldr
int ldr3 = A2; // left ldr
float stepsize = 1.8;
float angLR = 0.0;
}
void loop()
{
int right = analogRead(ldr1);
int centre = analogRead(ldr2);
int left = analogRead(ldr3);
if((right > centre) && (angLR >= -90.00 && angLR <= 90.00))
{
stepperh->onestep(BACKWARD,DOUBLE);
angLR += stepsize;
Serial.print("Angle LR °");
Serial.println(angLR);
}
if((left > centre) && (angLR >= -90.00 && angLR <= 90.00))
{
stepperh->onestep(FORWARD,DOUBLE);
angLR -= stepsize;
Serial.print("Angle LR °");
Serial.println(angLR);
}
}
Were right, left and centre are analog readings from LDR's. Everything works fine when "angLR" is between -90 and 90. But once angLR is -90 it wont move towards positive direction (even though the right LDR has more light). It should go -90,-89.2,-87.4,... instead it does nothing. Same thing in the other direction when angLR = +90.
Any help is appreciated.
Note: all LDR's are working correctly and are correctly assigned.