Make a void in a 'if' function

Hello,

I created a program

int pinLed3 = 8; // LED Blue
int pinLed2 = 6; // LED Green
int pinLed1 = 4; // LED Yellow
int pinLed0 = 2; // LED Red

int octetRecu;
void setup() {

Serial.begin(9600);

pinMode(pinLed0, OUTPUT);
pinMode(pinLed1, OUTPUT);
pinMode(pinLed2, OUTPUT);
pinMode(pinLed3, OUTPUT);
}
void loop() {

if (Serial.available() > 0) {

octetRecu = Serial.read();

if (octetRecu == 'R' || octetRecu == 'r') {
digitalWrite(pinLed0, HIGH);
Serial.println("LED Rouge allumee");
}

if (octetRecu == 'J' || octetRecu == 'j') {
digitalWrite(pinLed1, HIGH);
Serial.println("LED Jaune allumee");
}

if (octetRecu == 'V' || octetRecu == 'v') {
digitalWrite(pinLed2, HIGH);
Serial.println("LED Verte allumee");
}

if (octetRecu == 'B' || octetRecu == 'b') {
digitalWrite(pinLed3, HIGH);
Serial.println("LED Bleue allumee");
}

if (octetRecu == 'E' || octetRecu == 'e') {

digitalWrite(pinLed0, LOW);
digitalWrite(pinLed1, LOW);
digitalWrite(pinLed2, LOW);
digitalWrite(pinLed3, LOW);

Serial.println("LED eteinte");

}

if (octetRecu == 'A' || octetRecu == 'a') {

digitalWrite(pinLed0, HIGH);
digitalWrite(pinLed1, HIGH);
digitalWrite(pinLed2, HIGH);
digitalWrite(pinLed3, HIGH);

Serial.println("LED allumée");

}

if (octetRecu == 'G' || octetRecu == 'g') { // Want to create a loop

digitalWrite(pinLed0, HIGH);
delay(500);
digitalWrite(pinLed0, LOW);
delay(50);
digitalWrite(pinLed1, HIGH);
delay(500);
digitalWrite(pinLed1, LOW);
delay(50);
digitalWrite(pinLed2, HIGH);
delay(500);
digitalWrite(pinLed2, LOW);
delay(50);
digitalWrite(pinLed3, HIGH);
delay(500);
digitalWrite(pinLed3, LOW);
delay(50);

delay(10);

Serial.println("LED guirlande");
}
}
}

(u can download it ) and for the last 'if' function, I can't make a void for this function.

The DEL are HIGH just one time.

Can u help me?

Guillaume

(I am french so I have somes problems with english vocabulary)

Led_multifonction.ino (2.23 KB)

console-lumineuse-650px.JPG

Please explain what you mean by "make a void".

When you see things like:

void loop() {

The "void" part just indicates that the function doesn't return anything, just as:

byte someFunction() {

would indicate that the function returns a byte.

Are you saying that you want this section to repeat?

  if (octetRecu == 'G' || octetRecu == 'g') { // Want to create a loop
           
            digitalWrite(pinLed0, HIGH);
            delay(500);
            digitalWrite(pinLed0, LOW);
            delay(50);
            digitalWrite(pinLed1, HIGH);
            delay(500);
            digitalWrite(pinLed1, LOW);
            delay(50);
            digitalWrite(pinLed2, HIGH);
            delay(500);
            digitalWrite(pinLed2, LOW);
            delay(50);
            digitalWrite(pinLed3, HIGH);
            delay(500);
            digitalWrite(pinLed3, LOW);
            delay(50);

            delay(10);
            
            Serial.println("LED guirlande");
        }

What is going to control how many times it repeats?

If that's what you want then a simple for loop round most of it should be all it needs. If it's something else then we need a lot more detail of what exactly you need it to do that is different from what it does now.

Steve