Project 1.08 RGB Blink
In this project, we’ll blink the different colors of the RGB LED. The sketch is simple, but it’s long for what it does. In the next project, we’ll use more elegant programming to switch the RGB colors. Upload this sketch and then watch the RGB LED.
Concepts: variable delay, multichannel device
Circuits:
Concepts: variable delay, multichannel device
Circuits:
Each channel of the RGB LED is connected to a different pin on the Arno. We declare a variable for each pin at the beginning of the sketch:
int redLED = 9;
int greenLED = 10;
int blueLED = 11;
Likewise, we set each pinMode to an output in the setup() block:
pinMode(redLED,OUTPUT);
pinMode(greenLED,OUTPUT);
pinMode(blueLED,OUTPUT);
In the loop() block, we turn the colors on one after another. The time between changes is set by the variable wait. First red:
digitalWrite(blueLED,LOW);
digitalWrite(redLED,HIGH);
delay(wait);
Then green:
digitalWrite(redLED,LOW);
digitalWrite(greenLED,HIGH);
delay(wait);
And finally blue:
digitalWrite(greenLED,LOW);
digitalWrite(blueLED,HIGH);
delay(wait);
We reduce the value of wait to cycle through the colors faster and faster. When wait drops too low, we reset it to 250:
wait = wait - 10;
if(wait < 0) wait = 250;
int redLED = 9;
int greenLED = 10;
int blueLED = 11;
Likewise, we set each pinMode to an output in the setup() block:
pinMode(redLED,OUTPUT);
pinMode(greenLED,OUTPUT);
pinMode(blueLED,OUTPUT);
In the loop() block, we turn the colors on one after another. The time between changes is set by the variable wait. First red:
digitalWrite(blueLED,LOW);
digitalWrite(redLED,HIGH);
delay(wait);
Then green:
digitalWrite(redLED,LOW);
digitalWrite(greenLED,HIGH);
delay(wait);
And finally blue:
digitalWrite(greenLED,LOW);
digitalWrite(blueLED,HIGH);
delay(wait);
We reduce the value of wait to cycle through the colors faster and faster. When wait drops too low, we reset it to 250:
wait = wait - 10;
if(wait < 0) wait = 250;