How can you differentiate between delay commands in the same program?

I completed the last RGB program but I really didn't understand the commands. So I tried mixing the other two set ups and this is wwhat I got . (see video) Any tips to make it work better?

bekathwia1 month ago

I can't see your video but can you describe the behavior and show us your code modifications?

carlos-leal (author)  bekathwia1 month ago

Here is the code:

This example code is in the public domain.


int led = 9; // the PWM pin the LED is attached to

int led2 = 13;

int brightness = 0; // how bright the LED is

int fadeAmount = 5; // how many points to fade the LED by

// the setup routine runs once when you press reset:

void setup() {

// declare pin 9 to be an output:

pinMode(led, OUTPUT);

pinMode(led2, OUTPUT);


// the loop routine runs over and over again forever:

void loop() {

// set the brightness of pin 9:

analogWrite(led, brightness);

// change the brightness for next time through the loop:

brightness = brightness + fadeAmount;

// reverse the direction of the fading at the ends of the fade:

if (brightness <= 0 || brightness >= 255) {

fadeAmount = -fadeAmount;



{ digitalWrite(led2, HIGH); // turn the LED on (HIGH is the voltage level)

delay(100); // wait for a second

digitalWrite(led2, LOW); // turn the LED off by making the voltage LOW

delay(100); // wait for a second


// wait for 30 milliseconds to see the dimming effect