Go Down

Topic: Why won't this blink? (Read 485 times) previous topic - next topic

dglstrp

I am trying to get a timer to work using millis, when I run this in the Main Loop, the LED turns on (Gator+ board so LED inverted), runs for 10 seconds then turns off.
So the while statement is working, but why doesn't the LED blink?

if (serviceBypassTrigger == HIGH ) //let system open and close doors while error is live
{
 unsigned long errorClockStart = millis() + 10000;
 unsigned long errorClockCount = 0;
 while (errorClockCount < errorClockStart)
  {
  errorClockCount = millis();
 
  digitalWrite (errorLED,LOW);
  delay(500);
  digitalWrite (errorLED,HIGH);
  }

I just pasted the code cause it was so short.

robtillaart

#1
Dec 02, 2010, 05:22 pm Last Edit: Dec 02, 2010, 05:23 pm by robtillaart Reason: 1
It is allways better to paste the complete code because that makes it often much simpler to find bugs. This one is fairly easy, it will blink but you don't see it. After the errorled is made HIGH it is almost immediately made LOW again as there is no delay after the HIGH. Try this:
Code: [Select]

while (errorClockCount < errorClockStart)
 {
 errorClockCount = millis();

 digitalWrite (errorLED,LOW);
 [glow]delay(250);[/glow] // changed
 digitalWrite (errorLED,HIGH);
 [glow]delay(250);[/glow]  // added
 }

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

dglstrp

Thanks Robtillaart!
That nailed it!
I knew it HAD to be something simple!

robtillaart

Manually tracing the code and saying out loud what it does in plain english solves many bugs in software, give it a try!
Rob

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up