Hello,
I'm a beginner in "Arduino world" and I need some help.
I'm trying to create a code in which there are 8 LEDS :
- the LED1 and the LED2 have to blink without delay (LED1 - 50 milliseconds and LED2 - 100 milliseconds) ;
- the LED3 have to stay light ;
- the 5 others LEDS have to blink one by one (like the K2000's eye in the TV show) but without create a delay in the blink of LED1 and LED2.
To summarize, my problem is to find a way to combine these two codes :
Code 1 - LED1 / LED2 / LED3
const int ledAvantBlanche = 2;
const int ledAvantJaune = 3;
const int ledArriere = 4;
const unsigned long intervalLedAvantBlanche = 50;
const unsigned long intervalLedAvantJaune = 100;
void setup()
{
for (int led = 2; led < 5; led ++)
{
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
}
digitalWrite(ledArriere, HIGH);
}
void loop()
{
allumageLedAvantBlanche();
allumageLedAvantJaune();
}
void allumageLedAvantBlanche()
{
static unsigned long previousMillisLedAvantBlanche = 0;
static byte etatLedAvantBlanche = LOW;
unsigned long currentMillis = millis();
if (currentMillis - previousMillisLedAvantBlanche >= intervalLedAvantBlanche)
{
previousMillisLedAvantBlanche = currentMillis;
etatLedAvantBlanche = !etatLedAvantBlanche;
digitalWrite(ledAvantBlanche, etatLedAvantBlanche);
}
}
void allumageLedAvantJaune()
{
static unsigned long previousMillisLedAvantJaune = 0;
static byte etatLedAvantJaune = LOW;
unsigned long currentMillis = millis();
if (currentMillis - previousMillisLedAvantJaune >= intervalLedAvantJaune)
{
previousMillisLedAvantJaune = currentMillis;
etatLedAvantJaune = !etatLedAvantJaune;
digitalWrite(ledAvantJaune, etatLedAvantJaune);
}
}
Code 2 - the 5 others LEDS
int neon[5] = {8, 9, 10, 11, 12};
void setup()
{
for (int led = 8; led < 13; led ++)
{
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
}
}
void loop()
{
for (int ledBleueSens1 = 0; ledBleueSens1 < 4; ledBleueSens1 ++)
{
digitalWrite(neon[ledBleueSens1], HIGH);
delay(50);
digitalWrite(neon[ledBleueSens1], LOW);
delay(50);
}
for (int ledBleueSens2 = 4; ledBleueSens2 > 0; ledBleueSens2 --)
{
digitalWrite(neon[ledBleueSens2], HIGH);
delay(50);
digitalWrite(neon[ledBleueSens2], LOW);
delay(50);
}
}
I hope to have been clear in my question.
Thank you in advance for your help.