bool runAllowed = false;
void setup() {
// put your setup code here, to run once:
pinMode(5, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
runAllowed = digitalRead(5);
if(runAllowed)
{
for(int i=0; i<1000; i++)
{
runAllowed = digitalRead(5);// this should have to place inside the loop two . otherwise even input changed it'll not read/sense
Serial.print("i = ");
Serial.print(i);
Serial.print(" ");
Serial.println("Motor running");
if(not runAllowed)
{
break;
}
delay(500);
}
}
Serial.println("Motor not running");
delay(2000);
}