Hi all,
I've just got back into Arduino after 15+ years not touching them...
So, looking at some basic coding to flash some LEDs, i came across this problem....
For example, i'm trying to flash 1 LED (LED1) every 1 second, and flash another LED (LED2) every 200mSecs.
In my code here, clearly LED1 turns on/off before LED2 even gets a chance to switch on.
Is there a better way to nest these loops so the timing isn't delayed by waiting for one instruction to finish before the next instruction begins?
For example:
I'd be waiting 1.2 seconds before LED1 cycles on/off, instead of 1 second
I'd also be waiting 1.2 seconds before LED2 cycles on/off, instead of 200mSec.
int LED1=11;
int LED2=12;
void setup() {
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
}
void loop() {
digitalWrite(LED1,HIGH);
delay(1000);
digitalWrite(LED1,LOW);
delay(1000);
digitalWrite(LED2,HIGH);
delay(200);
digitalWrite(LED2,LOW);
delay(200);
}
Even if i interlace the commands to switch ON LED1 and LED2 immediately, then the 2 different delays upsets overall timing.
I'd like to see LED1 and LED2 switch on together and then continue flashing at their own rates.
This issue is highlighted further when i replace the delay times with 'random', which then speeds/slows the cycle of when LED2 with switch on/off after LED1 has completed its cycle after a 'random' amount of time (upto 1 second).
It seems like i need a command (or array?) that tells both (or more) pins to begin all at once, like a byte-wide operation?
Thanks in advance.