/*
munny_luces.ino
Juanjo García
20/12/23
Details available at https://docs.henhen1227.com/
*/
int LEDROJO = 0;
int LEDVERDE = 1;
int LEDAZUL = 2;
int BTN_GLOW = 5;
int BTN_COLOR = 4;
int buttonReadGlow;
int buttonReadColor;
int buttonReadGlowStart = 1;
int buttonReadColorStart = 1;
// defino el modo de color
int mode = 0;
int hex = 0;
int glow = 255;
void setup() {
pinMode(LEDROJO, OUTPUT);
pinMode(LEDVERDE, OUTPUT);
pinMode(LEDAZUL, OUTPUT);
pinMode(BTN_GLOW, INPUT_PULLUP);
pinMode(BTN_COLOR, INPUT_PULLUP);
Serial.begin(115200);
Serial.println("Setup");
}
void loop() {
buttonReadGlow = digitalRead(BTN_GLOW);
buttonReadColor = digitalRead(BTN_COLOR);
delay(100);
if (buttonReadGlow == 0 && buttonReadGlowStart == 1) {
if (glow >= 255) {
glow = 255 / 5;
} else {
glow = glow + (255 / 5);
}
buttonReadGlowStart = 0;
} else if (buttonReadGlow == 1 && buttonReadGlowStart == 0) {
buttonReadGlowStart = 1;
buttonReadColorStart = 1;
}
if (buttonReadColor == 0 && buttonReadColorStart == 1) {
if (mode >= 3) {
mode = 0;
} else {
mode = mode + 1;
}
buttonReadColorStart = 0;
} else if (buttonReadColor == 1 && buttonReadColorStart == 0) {
buttonReadGlowStart = 1;
buttonReadColorStart = 1;
}
checkMode(mode, glow);
}
void miColor(int rojo, int verde, int azul) {
analogWrite(LEDROJO, rojo);
analogWrite(LEDVERDE, verde);
analogWrite(LEDAZUL, azul);
}
/**
*/
void checkMode(int mode, int glow) {
if (mode == 0) {
miColor(glow, glow, glow);
}
if (mode == 1) {
miColor(glow, 0, 0);
}
if (mode == 2) {
miColor(0, glow, 0);
}
if (mode == 3) {
miColor(0, 0, glow);
}
}