/*
ARDUINO RGB LED TUTORIAL: Loop RGB
By: TheGeekPub.com
More Arduino Tutorials: https://www.thegeekpub.com/arduino-tutorials/
*/
const int PIN_RED1 = 4; //Red LED on pin 4
const int PIN_GREEN1 = 3; //Green LED on pin 3
const int PIN_BLUE1 = 2; //Blue LED on Pin 2
const int PIN_RED2 = 7; //Red LED on pin 7
const int PIN_GREEN2 = 6; //Green LED on pin 6
const int PIN_BLUE2 = 5; //Blue LED on Pin 5
const int PIN_RED3 = 10; //Red LED on pin 10
const int PIN_GREEN3 = 9; //Green LED on pin 9
const int PIN_BLUE3 = 8; //Blue LED on Pin 8
int led = 6; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
/* This function "Set Color" will set the color of the LED
rather than doing it over and over in the loop. */
void setColor(int R, int G, int B) {
analogWrite(PIN_RED1, 255);
analogWrite(PIN_GREEN1, 1);
analogWrite(PIN_BLUE1, 255);
analogWrite(PIN_RED2, 1);
analogWrite(PIN_GREEN2, 255);
analogWrite(PIN_BLUE2, 1);
analogWrite(PIN_RED3, 1);
analogWrite(PIN_GREEN3, 1);
analogWrite(PIN_BLUE3, 255);
analogWrite(led, brightness); // set the brightness of led
}
void setup() {
//set all three pins to output mode
pinMode(PIN_RED1, OUTPUT);
pinMode(PIN_GREEN1, OUTPUT);
pinMode(PIN_BLUE1, OUTPUT);
pinMode(PIN_RED2, OUTPUT);
pinMode(PIN_GREEN2, OUTPUT);
pinMode(PIN_BLUE2, OUTPUT);
pinMode(PIN_RED3, OUTPUT);
pinMode(PIN_GREEN3, OUTPUT);
pinMode(PIN_BLUE3, OUTPUT);
}
void loop() {
// set the colors of the LED
// Loop through Red-Green-Blue and repeat
setColor(255, 0, 0); //set LED to Red
delay(500);
setColor(0, 255, 0); //set LED to Green
delay(500);
setColor(0, 0, 255); //set LED to Blue
delay(500);
}