I would suggest using millis() instead of delay() inside the void loop() function to trigger your timed actions. To clear all leds does indeed take more time to clear just the one, but delay is also a blocking action, which means that nothing can happen while the MCU sleeps for the delay period. With millis() an action is triggered at a given interval, but the MCU can keep running and doing whatever tasks are needed without having to pause. This guide might be helpful:
I haven't tested this example, but maybe something like this:
#include "LedControl.h"
// LedControl(int dataPin, int clkPin, int csPin, int numDevices=1);
LedControl lc = LedControl(10, 9, 8, 1);
bool status = true;
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 500;
void setup()
{
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
startMillis = millis(); //initial start time
}
void mySetDisplay(bool state) {
for (int a = 0; a<8; a++) {
for (int b = 0; b<8; b++) {
lc.setLed(0, a, b, state);
}
}
}
void loop() {
currentMillis = millis(); //get the current millis
if (currentMillis - startMillis >= period) //test whether the period has elapsed
{
mySetDisplay(status);
status = ~status; // Flip status
startMillis = currentMillis; //IMPORTANT to save the start time of the current LED state.
}
}
I will let you correct anything that I might have missed... ![]()
Based on the linked guide. Hopefully you get the idea.
You can, of course, also have more than one time period defined for different actions or use multiples =, i.e (period * 2), (period * 3) or whatever and have additional if statements to test for them.