Author Options:

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

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?

2 Replies

bekathwia (author)2017-06-20

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

Select as Best AnswerUndo Best Answer

carlos-leal (author)bekathwia2017-06-21

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

Select as Best AnswerUndo Best Answer