My for statement is not working. It is suppose to loop as a time delay and while looping check to see if it sensor on the irpin goes low. The problem is it won't loop the delay it just keeps breaking out of the for. Any help would be most helpful.
Randy
for (int i=0; i <= 5000; i++) { // this is a timer loop with a break out if irpin 5 goes low
Don't know how much of a delay you expect, but 5000 iterations won't take very long to execute - a small fraction of a second, with the small amount of code that's executed in yours.
I would guess that loop would take ten or fifteen milliseconds to complete. If you want a longer delay, increase i or add a delay(1) and adjust the value of i to suit.
I don't think this code does anything useful - what is the purpose of the time delay? If the sensor is immediately low there will be no delay at all. What exactly are you trying to achieve?
I'm doing this off the top of my head without checking on my Arduino... be warned, be prepared to "get it right", but I hope you'll be able to see what I'm doing.
I think it is more clear than the original solution, and clarity leads to fewer bugs.
iLoopCount =5000;
do
{
sens = digitalRead(irpin);
dec(iLoopCount);
}
while ((iLoopCount>0)&&(sens>0));
//"&&" means "and"
===
Another solution would use the millis function... but would be subject to roll over errors every 9 hours.