Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Timer
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Timer

by keithg on Sat Apr 18, 2009 9:18 am

I need to stop a robot's motors after eight seconds. A search of past messages on the subject of TIMER points to a number of references to Timer1 and Timer0 without code examples. Would you please describe how this functions? Is a 555 timer in monostable mode an alternative?
keithg
 
Posts: 82
Joined: Thu Oct 30, 2008 8:30 pm

Re: Timer

by trialex on Sat Apr 18, 2009 8:05 pm

Surely the easiest way would be just to use a simple check to see whether millis() is greater than 8 seconds... check out the inbuilt "blink without delay" example sketch.
trialex
 
Posts: 189
Joined: Mon Apr 03, 2006 6:25 pm

Re: Timer

by keithg on Sat Apr 18, 2009 9:18 pm

Yes, I ran that sketch and played with the numbers but can't make it run just one time and stop, I mean a dead stop, exit the loop. Is it possible to write a "for... statement as a counter and use this timer without delay procedure? In other words, run this eight second loop only one time? I am working with several intro to C programming books but this is way ahead somewhere. Appreciate your help.
keithg
 
Posts: 82
Joined: Thu Oct 30, 2008 8:30 pm

Re: Timer

by trialex on Sun Apr 19, 2009 3:42 am

Yep well as usual there are a few ways to do it, I guess I'd format it like..

Code: Select all | TOGGLE FULL SIZE
while (elapsed time < 8 seconds){
       run the motor
       }
turn off the motor
while (1){}     // This is an empty loop that runs for ever
trialex
 
Posts: 189
Joined: Mon Apr 03, 2006 6:25 pm

Please be positive and constructive with your questions and comments.