Reputation: 1
My situation I'm using shift registers to control 72 LEDs individal. Each LED can be activated via a specific request. It is easy to set the LED to HIGH, but the LED should blink. Making the LED blink via "for" is not a problem. I managed to make the LED blinking, once it it blinking it does not stop when a new request comes in. The LED should blink only till a new request arrives.
My problem is if during the blinking peroid (in the example 3 times) I can not stop it. If I'm sending a new if(readString.indexOf("?button1onA2") > 0)
for example for an other LED (?button1onA2) the request will be ignored as long as the LED from the request before is still blinking.
My target is to make the LED blink, but stop when a new request via 'readstring' arrives.
My Question:
for (i = 0; i < 3; i++)
?My code
if (readString.indexOf("?button1onA1") > 0)
In this case the LED with the sensor ID 4 should blink.
if (readString.indexOf("?button1onA1") > 0) {
for (i = 0; i < 3; i++)
{
shifter.setPin(4, HIGH);
shifter.write();
delay(200);
shifter.setPin(4, LOW);
shifter.write();
delay(200);
}
Upvotes: 0
Views: 452
Reputation: 3739
You have to use non blocking delays (e.g., Blink Without Delay). A good way is also using state machine (or many of them).
But in theory, you can just store bitmasks for the LEDs, that should blink, and blink them all synchronously (with non blocking delays).
Upvotes: 1