Pages: [1]   Go Down
Author Topic: Why won't this blink?  (Read 462 times)
0 Members and 1 Guest are viewing this topic.
Utah
Offline Offline
Newbie
*
Karma: 0
Posts: 24
High Priced Toy Specialist
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 227
Posts: 14048
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
while (errorClockCount < errorClockStart)
  {
  errorClockCount = millis();
 
  digitalWrite (errorLED,LOW);
  [glow]delay(250);[/glow] // changed
  digitalWrite (errorLED,HIGH);
  [glow]delay(250);[/glow]  // added
  }
« Last Edit: December 02, 2010, 11:23:28 am by robtillaart » Logged

Rob Tillaart

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

Utah
Offline Offline
Newbie
*
Karma: 0
Posts: 24
High Priced Toy Specialist
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 227
Posts: 14048
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Logged

Rob Tillaart

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

Pages: [1]   Go Up
Jump to: