Hello, i need ur help. Currently i using delay(), but i dont want use more this function. Looking at internet i saw millis(), but i totaly dont understand how works. Nvm.. I need simple time counter. Somethink like blinking without delay();
for(int forCount = 0; forCount < 12; forCount++)
{
digitalWrite(seq1[forCount],output1[forCount]);
==TIME== to run next LED
};
If you post your existing sketch which includes delay() statements, it may be clearer what you want to achieve.
From the code you have supplied you could be lighting a series of 12 leds sequentially, each for a specific time interval.
f.e.:
int delayTime[] = {1000, 20000, 3000, 7000, 3000, 52000, 5000, 5000, 4000, 19000, 2000};
i know that, so i made it before, but only need the simplest timer
Are these timings sequential ? In other words does LED0 light for 1000mS then go out, then LED1 lights for 20,000 mS then goes out etc.
If so, you can do something like this incorporated into your loop structure :
loop() {
. . .
ms = millis() - cycleStart() ; // milliseconds into cycle
if ( ms > Sum_of_all_delays ) {
cycleStart = millis() ; // restart cycle
ms = 0 ;
}
if ( ms >= 0 && ms < 1000 ) LED0 = HIGH ; // also ensure all other LEDS are off if required.
if ( ms >= 1000 && ms < 21000 ) LED1 = HIGH ; // also ensure all other LEDS are off if required.
// etc
. . .
}
I guess, by the way that your requirements are being slowly revealed, that this is school work. If you "didnt understood nothin'" and you have been asked to do this exercise without using the delay() statement, you have a problem.
In principle, the millis() function is a counter of the number of milliseconds which have elapsed since the arduino was started. By calculating the difference between the current value of millis() and a value of millis() at event in the past (stored in a variable), you can determine if that event happened so long ago (expiry) that some action must be initiated.
In your case, once a led is lit, a counter starts and you continuously check for its expiry so that you can then light the next LED in the series and repeat the whole thing.