Hi friends, i need help about programming here my project is using RFID to Active Motor Servo and waiting until limit switch pressed then Motor servo turn back, i need to use Limit swicth for change the color of led. Here is my primary code :
void loop ()
{
int successRead;
do
{
successRead = getID();
}
while (!successRead);
if (isMaster(readCard)) // if card match
{
Serial.println("Go in");
Serial.println("");
Serial.println("===================================================");
Serial.println("");
digitalWrite(b, LOW); // LED Blue change to...
digitalWrite(g, HIGH); // LED Green on
beep3(buzz); // buzz on
c=90; //servo angle
d=40; //delay servo
for (a=0;a<=c;a+=5)
{
servo1.write(a);
delay(d);
}
//LIMIT SWITCH --<<< Here is my problem
val = digitalRead(inLimit);
Serial.println(val);
if(val == HIGH){
Serial.println(val);
Serial.println("test");
for (a=c;a>0;a-=5) // servo turn back
{
servo1.write(a);
delay(d);
}
digitalWrite(b, HIGH); // LED Blue again
digitalWrite(g, LOW); // Green off
}
}
else // if card not match
{
Serial.println("Warning");
Serial.println("");
Serial.println("===================================================");
Serial.println("");
digitalWrite(r, HIGH); // LED red active,
digitalWrite(b, LOW);
beep2(buzz); // Buzzer long,
digitalWrite(b, HIGH); // then LED blue On again
digitalWrite(r, LOW); // LED Red off
}
}
My problem is in execution for Limit Switch , when i give my
- RFID card matched
- LED from BLUE change to GREEN ON
- then LED GREEN ON and waiting until the Limit Switch is pressed
- When i press Limit switch thats nothing change (i mean still in LED GREEN ON)
- I try to press limit switch again still nothing changes.
Thats my problem, maybe anyone can help me about my script. Thanks for attention. Sry about my english is not good.