///////////////////////////////////////////////////////////////////////////////////////////
//Diagram tienen una correcion de la graducion del color por el gamma para los LEDS!!!!!!!!
///////////////////////////////////////////////////////////////////////////////////////////
#define LED1 22
#define LED2 23
#define BTN1 4
#define BTN2 5
//Estados Boton
int BTN1_estado = 0;
int BTN2_estado = 0;
int BTN1_Push = 0;
int BTN2_Push = 0;
int Boton1 = 0;
int Boton2 = 0 ;
//Estado LEDS
int LED1_state = LOW;
int brightness = 100;
int brightnessW = 100;
int jumpBrig1 = 10;
int jumpBrig2 = 10;
//tiempo real cehck
unsigned long ms = millis();
int Pre_ms = 0;
int CheckMillms = 30;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(BTN1, INPUT_PULLUP);
pinMode(BTN2, INPUT_PULLUP);
}
void loop() {
unsigned long ms = millis();
Boton1 = digitalRead(BTN1);
Boton2 = digitalRead(BTN2);
analogWrite(LED2, brightnessW);
Serial.print("Brilllos");
Serial.print(brightness);
Serial.print("Brilllos");
Serial.print(brightnessW);
Serial.print("|| BTN1_Push :");
Serial.print(BTN1_Push);
Serial.print("|| BTN2_Push :");
Serial.print(BTN2_Push);
Serial.print("|| BTN1:");
Serial.print(Boton1);
Serial.print("|| BTN2:");
Serial.println(Boton2);
if ((digitalRead(BTN1) == LOW) && (BTN1_Push == 0) ){
BTN1_Push = 1;
if (brightnessW < 250){
brightnessW = brightnessW + jumpBrig2;
}
}
else if ((digitalRead(BTN2) == LOW) && (BTN2_Push == 0) ){
BTN2_Push = 1;
if (brightnessW > 0){
brightnessW = brightnessW - jumpBrig2;
}
}
if ((digitalRead(BTN1) == HIGH) && (BTN1_Push == 1) ){
BTN1_Push = 0;
}
else if ((digitalRead(BTN2) == HIGH) && (BTN2_Push == 1) ){
BTN2_Push = 0;
}
//set the brightness of pin 9:
if (ms - Pre_ms > CheckMillms){
analogWrite(LED1, brightness);
// change the brightness for next time through the loop:
brightness = brightness + jumpBrig1;
// reverse the direction of the fading at the ends of the fade:
if (brightness <= 0 || brightness >= 255) {
jumpBrig1 = -jumpBrig1;
}
// wait for 30 milliseconds to see the dimming effect
Pre_ms = ms;
}
}