I was wondering if it would be possible to run 2 or more loops at the same time with an Arduino. I want to have a few LEDs blink (go around in a circle) while having another (in the middle of the others) use PWM. I already tried making another void loop, but it does not work. Here is the code that I have been using:
int red = 6;
int brightness = 0;
int fadeAmount = 4;
int green1 = 13;
int blue1 = 12;
int yellow1 = 11;
int green2 = 10;
int blue2 = 9;
int yellow2 = 8;
void setup() {
pinMode(red, OUTPUT);
pinMode(yellow1, OUTPUT);
pinMode(green1, OUTPUT);
pinMode(blue1, OUTPUT);
pinMode(yellow2, OUTPUT);
pinMode(green2, OUTPUT);
pinMode(blue2, OUTPUT);
}
void loop() {
analogWrite(red, brightness); // this first part was copied from the "Fade" example with some small modifications (pin numbers, brightness)
brightness = brightness + fadeAmount;
if (brightness == 0 || brightness == 255) {
fadeAmount = -fadeAmount ;
}
delay(10);
// I want to have everything below this be part of a seperate loop
digitalWrite(green1, 1);
digitalWrite(yellow2, 0);
delay(100);
digitalWrite(blue1, 1);
digitalWrite(green1, 0);
delay(100);
digitalWrite(yellow1, 1);
digitalWrite(blue1, 0);
delay(100);
digitalWrite(green2, 1);
digitalWrite(yellow1, 0);
delay(100);
digitalWrite(blue2, 1);
digitalWrite(green2, 0);
delay(100);
digitalWrite(yellow2, 1);
digitalWrite(blue2, 0);
delay(100);
}
I have been using an Arduino Leonardo and the sections work fine separately; I just want them to use different pins and run independently, but at the same time.