I have the aim to control 60 single LEDs in one way (delay of 1 minute between each turning on), and 12 single LEDs in another way (1 hour delay between each). Does anyone know of a way that this is possible?
Is it possible to have two 'for' loops running at the same time? Is it even possible using only one arduino?
Didn't we already discuss this? Use MAX7219 to control 64 LEDs, Arduino outputs for the other 8.
Or use 17 pins and control a 8x9 matrix.
Once a minute, update all your outputs.
This gives the basic outline, how you update things is based on what you use for the LED drives.
All time related variables are unsigned long.
void loop(){
currentMillis = millis();
elapsedMinute = currentMillis - previousMinute;
if (elapsedMinute >= oneMinute){ // minute passed, update minute & hour counters
previousMinute = previousMinute + oneMinute; // set for next time check
oneMinute = oneMinute +1;
if (oneMinute == 60){ // 0 to 59
displayUpdateFlag =1;
oneMinute = 0;
oneHour = oneHour +1;
if (oneHour == 12){ // 0 to 11
oneHour = 0;
} // end hr rollovercheck
} // end minute rollover check
} // end minute duration
if (displayUpdateFlag == 1){ // do whatever needed to drive your outputs if static output
displayUpdateFlag = 0; // clear for next pass thru loop
// update MAX7219 registers, send new data to shift registers
}
// OR, if driving your own multiplexing
elapsedMultiplex = currentMillis - previousMultiplex;
if (elapsedMultiplex >= duration){ // duration like 1mS
previousMultiplex = previousMultiplex + duration;
// update the outputs based on settings of oneMinute, oneHour
}
} // end loop
Hello, thank you very much for the reply (replies) (I just wanted to get a few opinions from multiple forums).
I am very grateful for the code; I am a bit new to programming so I kinda get it and kinda don't (I have not come across a few of the things here).
Could you possibly tell me which big causes it to cycle through LEDs 1-60 for the minutes, and which bit cycles through LEDs 1-12 in intervals of hours?
I think I am starting to understand the code. Sorry for going on (I am quite new to this) but do you know of any good online material that can teach me how this code is working?
This forum is a good way for that, but also the examples that came with IDE.
Those examples do not show you how to do exactly what you are working on here.
But they will teach you some basic knowledge about building sketches.
The answer to you question is addressed in the "blink without delay" sketch, if you understand that you should be able to work this all out.
That is about non blocking code.
Delays are extremely blocking, but so are (large) for.. loops.
Take small (baby)steps, to keep things clear and do not try to skip steps.
CrossRoads already has put you on this route by his example that does handle the minutes and hours counting.
It's good for you to ask questions if you do not understand something.
There's a lot of people that want to help.
If your questions are clear and to the point, so will be the answers.
So what is it that you do not yet get about that last code block CrossRoads has shown you ?
Or do you have some other question ?
Thanks, sorry for the late reply, I have been a bit stressed finishing my dissertation.
The bit in the code that I do not really get is which bit cycles through the LEDS? Which bit tells the next LED in line to come on every minute (or hour)?
I am also not familiar with the displayupdateflag function.
if (displayUpdateFlag == 1){ // do whatever needed to drive your outputs if static output
displayUpdateFlag = 0; // clear for next pass thru loop
// update MAX7219 registers, send new data to shift registers
}
// OR, if driving your own multiplexing
elapsedMultiplex = currentMillis - previousMultiplex;
if (elapsedMultiplex >= duration){ // duration like 1mS
previousMultiplex = previousMultiplex + duration;
// update the outputs based on settings of oneMinute, oneHour
}
It's really dependent on how you are driving the LEDs. I haven't seen a hint of what you are planning on.
The displayupdateflag just tells one part of the code that another has detected a minute and/or hour has passed, the variables for them have been updated, so change the output display.