//C++ Code - Reto # 1 - Class 5 Microcontrolers
// Define the pins for Red, Green, and Blue LEDs
const int redPin = 2;
const int greenPin = 4;
const int bluePin = 5;
void setup() {
Serial.begin(9600);
// Initialize the RGB LED pins as OUTPUT
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop() {
// Set the RGB LED to different colors
setColor(0, 100, 255); // amarillo
delay(5000);
setColor(130, 0, 255); // transicion
delay(2000);
setColor(255, 0, 255); // verde
delay(5000);
setColor(0, 170, 255); // transicion
delay(2000);
setColor(0, 255, 255); // rojo
delay(5000);
fin(0, 255, 0);
}
// Function to set the color of the RGB LED
void setColor(int red, int green, int blue) {
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
void fin(int red, int green, int blue){
for (int i=0; i<=10; i++){
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
delay(150);
analogWrite(redPin, 255);
analogWrite(greenPin, 255);
analogWrite(bluePin, 255);
delay(150);
}
}