BLINK RGB COLOURS & WHITE LEDs

Goal: Create a method where all LEDs on the Protosnap (see image) will blink in order: RGB Red, RGB Green, RGB Blue, LED 5, LED 6, LED A2, LED A4, LED A3.

I know how to do this if I put it in a loop, but I'm not sure how I'd go about doing it if I only wanted the lights to each blink once...

Greatly appreciate any help I can get - thanks in advance

Here's the code I've developed so far:

int LED5 = 5; // LED is connected to digital pin 5
int LED6 = 6; // LED is connected to digital pin 6
int redPin = 9; // R petal on RGB LED module connected to digital pin 11
int greenPin = 11; // G petal on RGB LED module connected to digital pin 9
int bluePin = 10; // B petal on RGB LED module connected to digital pin 10
int delayTime = 200; // delay is 1/5 of a second

void setup(){
pinMode(LED5, OUTPUT); // sets the LED 5 to be an output
pinMode (LED6, OUTPUT); // sets the LED 6 to be an output
pinMode (A2, OUTPUT); // sets the LED A2 to be an output
pinMode (A4, OUTPUT); // sets the LED A4 to be an output
pinMode (A3, OUTPUT); // sets the LED A3 to be an output
pinMode(redPin, OUTPUT);// sets the redPin (9) to be an output
pinMode(greenPin, OUTPUT); // sets the greenPin (11) to be an output
pinMode(bluePin, OUTPUT); // sets the bluePin (10) to be an input
rgbLight (0,0,0);
}

void loop(int red, int green, int blue) { // run forever
}

void rgbLight (int red, int green, int blue){
analogWrite(redPin, 255-100);
analogWrite(bluePin, 255-50);
analogWrite(greenPin, 255-100);
rgbLight(255,0,0); //turn the RGB LED red
delay(delayTime); //delay
rgbLight(0,0,0); //turn the RGB LED red
delay(delayTime); //delay
rgbLight(0,255,0); //turn the RGB LED green
delay(delayTime); //delay
rgbLight(0,0,0); //turn the RGB LED red
delay(delayTime); //delay
rgbLight(0,0,255); //turn the RGB LED blue
delay(delayTime); //delay
rgbLight(0,0,0); //turn the RGB LED red
delay(delayTime); //delay
digitalWrite (LED5, HIGH);
delay (delayTime);
digitalWrite (LED5, LOW);
delay (delayTime);
digitalWrite (LED6, HIGH);
delay (delayTime);
digitalWrite (LED6, LOW);
delay (delayTime);
digitalWrite (A2, HIGH);
delay (delayTime);
digitalWrite (A2, LOW);
delay (delayTime);
digitalWrite (A4, HIGH);
delay (delayTime);
digitalWrite (A4, LOW);
delay (delayTime);
digitalWrite (A3, HIGH);
delay (delayTime);
digitalWrite (A3, LOW);
delay (delayTime);
}

index.jpg

I'm not sure how I'd go about doing it if I only wanted the lights to each blink once..

Put the code in setup() and it will only run once or put it in a function and call that function only when a trigger event occurs.

Shorten the code drastically by putting the pin numbers in an array and iterating through it with a for loop.

Having said that, your major mistake is that the rgbLight() function calls itself recursively. Do not do this unless you know exactly what you are doing.

When posting code please use code tags, see read this before posting a programming question, and post complete programs.

// blink in order: RGB Red, RGB Green, RGB Blue, LED 5, LED 6, LED A2, LED A4, LED A3.
const byte Pins[] = {9, 11, 10, 5, 6, A2, A4, A3};
const byte Count = sizeof Pins / sizeof Pins[0];  // Calculate the number of elements in an array


void setup() {
  // Set initial state and pin mode
  for (int i=0; i<Count; i++) {
    digitalWrite(Pins[i], LOW);
    pinMode(Pins[i], OUTPUT);
  }

  delay(1000);

  // Blink in sequence
  for (int i=0; i<Count; i++) {
    digitalWrite(Pins[i], HIGH);
    delay(200);
    digitalWrite(Pins[i], LOW);
    delay(200);  // Optional if you want off time between LEDs
  }
}

void loop() {}

Wait but using the code above, the RGB LED is just white (I'm assuming all 3 colours are on?)...

The bottom 5 LEDs blink perfectly, but what would I have to modify in order to make the RGB blink its 3 colours?

Thanks for all the guidance

The problem is that the RGB is a Common Anode type so the common is wired to +5V and you light the LED by setting the pin LOW. Power then flows from the+5V pin through the LED to the control pin.

To fix the problem we have to invert the signal for those three pins. To do that we add another array that gives the OnValue for each of the pins (LOW or HIGH). We can turn the LED on by setting the pin to OnValue and turn it off by setting it to the logical inverse of that value: !OnValue.

// blink in order: RGB Red, RGB Green, RGB Blue, LED 5, LED 6, LED A2, LED A4, LED A3.
const byte Pins[] = {9, 11, 10, 5, 6, A2, A4, A3};
const byte Count = sizeof Pins / sizeof Pins[0];  // Calculate the number of elements in an array
// Now that we have calculated the number of pins we specify that as the size of the other array(s).
// This allows the compiler to warn us if we put in the wrong number of initializers.
const boolean OnValue[Count] = {LOW, LOW, LOW, HIGH, HIGH, HIGH, HIGH, HIGH};

void setup() {
  // Set initial state and pin mode
  for (int i=0; i<Count; i++) {
    digitalWrite(Pins[i], !OnValue[i]);
    pinMode(Pins[i], OUTPUT);
  }

  delay(1000);

  // Blink in sequence
  for (int i=0; i<Count; i++) {
    digitalWrite(Pins[i], OnValue[i]);
    delay(200);
    digitalWrite(Pins[i], !OnValue[i]);
    delay(200);  // Optional if you want off time between LEDs
  }
}

void loop() {}