#include <Servo.h>
Servo barrera;
const int RGB_ROJO = 11;
const int RGB_VERDE = 10;
const int RGB_AZUL = 9;
void encenderRGB(int r, int g, int b) {
analogWrite(RGB_ROJO, r);
analogWrite(RGB_VERDE, g);
analogWrite(RGB_AZUL, b);
}
void setup() {
barrera.attach(5);
}
void loop() {
// Enciende RGB ROJO
encenderRGB(255, 0, 0);
// Servo en 0 grados
barrera.write(0);
delay(3000);
// Cambia posicion servo a 90 grados
for(int i = 0; i < 90; i++) {
barrera.write(i);
delay(50);
// Si la posicion del servo es 45 RGB es amarillo
if (i == 45) {
encenderRGB(255, 255, 0);
}
}
// Cambia posicion servo a 0 grados
for(int j = 90; j > 0; j--) {
barrera.write(j);
delay(50);
}
}