int bluePin = 9;
int greenPin = 10;
int redPin = 11;
int botonPin = 12;
int estadoLED = 0;
int botonNew;
int botonOld = 1;
int dt = 100;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(redPin, OUTPUT); //Set redPin to be an output
pinMode(greenPin, OUTPUT); //Set greenPin to be an output
pinMode(bluePin, OUTPUT); //set bluePin to be an output
pinMode(botonPin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
botonNew = digitalRead(botonPin);
Serial.println(botonNew);
if (botonOld == 0 && botonNew == 1) {
switch (estadoLED) {
case 0:
setColor(255, 255, 0); // yellow Color
Serial.print("Estas en la pulsación ");
Serial.print(estadoLED+1);
Serial.println(" del botón y está mostrando el color AMARILLO");
estadoLED++;
break;
case 1:
setColor(0, 255, 0); // Green Color
Serial.print("Estas en la pulsación ");
Serial.print(estadoLED+1);
Serial.println(" del botón y está mostrando el color VERDE");
estadoLED++;
break;
case 2:
setColor(0, 0, 255); // Blue Color
estadoLED++;
break;
case 3:
setColor(255, 255, 255); // White Color
Serial.print("Estas en la pulsación ");
Serial.print(estadoLED+1);
Serial.println(" del botón y está mostrando el color AZUL");
estadoLED++;
break;
case 4:
setColor(170, 0, 255); // Purple Color
Serial.print("Estas en la pulsación ");
Serial.print(estadoLED+1);
Serial.println(" del botón y está mostrando el color VIOLETA");
estadoLED++;
break;
case 5:
setColor(255, 0, 0); // Red Color
Serial.print("Estas en la pulsación ");
Serial.print(estadoLED+1);
Serial.println(" del botón y está mostrando el color ROJO");
break;
estadoLED = 0;
default:
setColor(0, 0, 0); // White Color
}
}
botonOld = botonNew;
delay(dt);
}
void setColor(int redValue, int greenValue, int blueValue) {
Serial.println();
analogWrite(redPin, redValue);
Serial.println(redValue);
analogWrite(greenPin, greenValue);
Serial.println(greenValue);
analogWrite(bluePin, blueValue);
Serial.println(blueValue);
Serial.println();
}