#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED width, in pixels
#define SCREEN_HEIGHT 64 // OLED height, in pixels
// create an OLED display object connected to I2C
Adafruit_SSD1306 oled(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
const unsigned char NaN [] PROGMEM = {
// 'descargar, 64x64px
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0xf8, 0x00, 0x00, 0x00,
0x00, 0x00, 0x03, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x3f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00,
0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00,
0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00,
0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80,
0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0,
0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0,
0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x1f, 0xff, 0xf8, 0x01, 0xf0, 0x00, 0x7f, 0xf0,
0x1f, 0xff, 0xf8, 0x01, 0xe0, 0x00, 0x0f, 0xf8, 0x3f, 0xff, 0xf8, 0x01, 0xe0, 0x00, 0x07, 0xf8,
0x3f, 0xff, 0xff, 0x83, 0xe0, 0x7f, 0x03, 0xf8, 0x3f, 0xff, 0xff, 0x83, 0xc0, 0x7f, 0x83, 0xfc,
0x7f, 0xff, 0xff, 0x03, 0xc0, 0xff, 0x07, 0xfc, 0x7f, 0xff, 0xff, 0x07, 0xc0, 0xfe, 0x07, 0xfc,
0x7f, 0xff, 0xff, 0x07, 0x80, 0x00, 0x0f, 0xfe, 0x7f, 0xff, 0xfe, 0x07, 0x80, 0x00, 0x1f, 0xfe,
0x7f, 0xff, 0xfc, 0x0f, 0x80, 0x00, 0xff, 0xfe, 0xff, 0xff, 0xf8, 0x1f, 0x01, 0xff, 0xff, 0xfe,
0xff, 0xff, 0xe0, 0x3f, 0x01, 0xff, 0xff, 0xfe, 0xff, 0x80, 0x00, 0x7e, 0x03, 0xff, 0xff, 0xfe,
0xff, 0x80, 0x01, 0xfe, 0x03, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
0xff, 0xe0, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xfe, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe,
0x7f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x7f, 0xf0, 0xf7, 0x06, 0x80, 0xe1, 0xbf, 0xfc,
0x7f, 0xe7, 0x24, 0xfc, 0xe7, 0x9d, 0xbf, 0xfc, 0x7f, 0xe7, 0x6d, 0xed, 0xe7, 0xb9, 0x3f, 0xfc,
0x3f, 0xee, 0x6d, 0xc9, 0xef, 0x31, 0x3f, 0xfc, 0x3f, 0xc0, 0xcc, 0x19, 0xcf, 0x7b, 0x87, 0xf8,
0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0,
0x1f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x0f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0,
0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0,
0x03, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xc0, 0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x80,
0x01, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x00,
0x00, 0x7f, 0xff, 0xff, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xf8, 0x00,
0x00, 0x1f, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x00, 0x00, 0x07, 0xff, 0xff, 0xff, 0xff, 0xe0, 0x00,
0x00, 0x03, 0xff, 0xff, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
0x00, 0x00, 0x3f, 0xff, 0xff, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0xff, 0xf0, 0x00, 0x00,
0x00, 0x00, 0x01, 0xff, 0xff, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xe0, 0x00, 0x00, 0x00
};
int i=0,kp=25,ki=10,kd=2,sp=50,rct=10,tau=30,t=35;
float temp_d=0,tiem_d=0;
int menu=0,ba=0,b1=0,b2=0,b3=0,menu_e=0;
float tmp_1=0,tmp_2=0;
const int set=18,up=5,down=4;
void setup() {
pinMode(set, INPUT);
pinMode(up, INPUT);
pinMode(down, INPUT);
Serial.begin(9600);
// initialize OLED display with I2C address 0x3C
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("failed to start SSD1306 OLED"));
while (1);
}
// wait two seconds for initializing
oled.clearDisplay(); // clear display
//oled.setTextSize(1); // set text size
//oled.setTextColor(WHITE); // set text color
//oled.setCursor(0, 10); // set position to display
//oled.println("esp32io.com"); // set text
//oled.display();
oled.drawBitmap(32,0,NaN,64,64,WHITE);
oled.display();
delay(5000);
oled.clearDisplay();
}
void loop() {
tmp_1=millis();
if((tmp_1-tmp_2)>=100){
tmp_2=millis();
oled.clearDisplay();
temp_d=i/1000.0;
tiem_d=i/150.0;
if(digitalRead(up)&&menu==0){b1++;b2=0;if(b1==2*10){menu=1;b1=0;ba=1;}}else{b1=0;}
if(digitalRead(down)&&menu==0){b2++;b1=0;if(b2==2*10){menu=2;b2=0;ba=1;}}else{b2=0;}
if(digitalRead(up)&&digitalRead(down)&&menu==0){b3++;b1=0,b2=0;if(b3==2*10){menu=3;b3=0;}}else{b3=0;}
}
i++;
switch (menu){
case 1:
conf_sp();
break;
case 2:
conf_t();
break;
case 3:
conf_esp();
break;
default:
prin();
break;
}
}
void prin(){
oled.setTextSize(1);
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 10); // set position to display
oled.printf("Temperatura\n%d %f\n",sp,temp_d);
oled.printf("Tiempo\n%d %f\n",t,tiem_d);
oled.display();
}
void conf_sp(){
oled.setTextSize(1);
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 0); // set position to display
oled.printf("Configuracion\nTemperatura\n%d",sp);
oled.display();
if(digitalRead(up)){if(ba==0){sp++;oled.clearDisplay();}}else{ba=0;}
if(digitalRead(down)){sp--;oled.clearDisplay();}
if(digitalRead(set)){menu=0;}
delay(10);
}
void conf_t(){
oled.setTextSize(1);
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 0); // set position to display
oled.printf("Configuracion\nTiempo\n%d",t);
oled.display();
if(digitalRead(up)){t++;oled.clearDisplay();}
if(digitalRead(down)){if(ba==0){t++;oled.clearDisplay();}}else{ba=0;}
if(digitalRead(set)){menu=0;}
delay(10);
}
void conf_esp(){
oled.setTextSize(1);
oled.setTextColor(WHITE); // set text color
oled.setCursor(0, 0); // set position to display
oled.printf("Configuraciones\nEspeciales\n");
if(digitalRead(set)){menu_e++;}
delay(100);
switch(menu_e){
case 0:
conf_rct();
break;
case 1:
conf_tau();
break;
case 2:
conf_kp();
break;
case 3:
conf_ki();
break;
case 4:
conf_kd();
break;
}
if(menu_e>5){menu_e=0;menu=0;}
}
void conf_rct() {
oled.setCursor(0, 16); // set position to display
oled.printf("Configuracion\nRCT\n%d",rct);
oled.display();
if(digitalRead(up)){rct++;oled.clearDisplay();}
if(digitalRead(down)){rct--;oled.clearDisplay();}
delay(10);
}
void conf_tau(){
oled.setCursor(0, 16); // set position to display
oled.printf("Configuracion\nLlegada\n%d",tau);
oled.display();
if(digitalRead(up)){tau++;oled.clearDisplay();}
if(digitalRead(down)){tau--;oled.clearDisplay();}
delay(10);
}
void conf_kp(){
oled.setCursor(0, 16); // set position to display
oled.printf("Configuracion\nKP\n%d",kp);
oled.display();
if(digitalRead(up)){kp++;oled.clearDisplay();}
if(digitalRead(down)){kp--;oled.clearDisplay();}
delay(10);
}
void conf_ki(){
oled.setCursor(0, 16); // set position to display
oled.printf("Configuracion\nKI\n%d",ki);
oled.display();
if(digitalRead(up)){ki++;oled.clearDisplay();}
if(digitalRead(down)){ki--;oled.clearDisplay();}
delay(10);
}
void conf_kd(){
oled.setCursor(0, 16); // set position to display
oled.printf("Configuracion\nKD\n%d",kd);
oled.display();
if(digitalRead(up)){kd++;oled.clearDisplay();}
if(digitalRead(down)){kd--;oled.clearDisplay();}
delay(10);
}