//https://github.com/ThingPulse/esp8266-oled-ssd1306
#include "SSD1306.h"
#define led 12 // led en placa
SSD1306 display(0x3c, 5, 4);
unsigned long previousMillis = 0;
const long interval = 500;
bool estado=0;
int porcentajeBateria=101;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
display.init();
display.flipScreenVertically (); // descomentar para la placa 18650
display.clear();
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
digitalWrite(LED_BUILTIN, estado);
estado=estado-1;
porcentajeBateria--;
bateria();
}
if (porcentajeBateria==0)porcentajeBateria=100;
}
void bateria(){
display.fillRect(125,6,3,6); // bata pico
display.drawRect(108,3, 18, 12); // bata
if (porcentajeBateria >= 40) display.fillRect(110, 5, 4, 8); // 33 %
if (porcentajeBateria >= 66) display.fillRect(115, 5, 4, 8); // 66 %
if (porcentajeBateria >= 92) display.fillRect(120, 5, 4, 8); // 99 %
if(estado==0){
display.setFont(ArialMT_Plain_10);
display.setColor(BLACK); // PARA BORRAR SOLO LA BATA
//if(porcentajeBateria<=10)display.fillRect(108,3,20,12); // bata entera
// else
display.fillRect(109,4,16,10); // dentro bata
display.setColor(WHITE);
display.drawString(110, 3, "full");
}
display.drawLine(0, 1, 127, 1);
display.drawLine(0, 16, 127, 16);
display.setColor(BLACK);
display.fillRect(41,24,42,26); // borro porcentaje
display.setColor(WHITE);
display.setFont(ArialMT_Plain_24);
display.drawString(44, 25, String(porcentajeBateria));
display.display();
}
/*
void bateria(){
display.fillRect(18,6,2,6); // bata pico
display.drawRect(0,3, 18, 12); // bata
if (porcentajeBateria >= 45) display.fillRect(2, 5, 4, 8); // 33 %
if (porcentajeBateria >= 65) display.fillRect(7, 5, 4, 8); // 66 %
if (porcentajeBateria >= 82) display.fillRect(12, 5, 4, 8); // 99 %
if(estado==0){
display.setColor(BLACK); // PARA BORRAR SOLO LA BATA
if(porcentajeBateria<=10)display.fillRect(0,3,20,12); // bata entera
else display.fillRect(1,4,16,10); // dentro bata
display.setColor(WHITE);
}
display.drawLine(0, 1, 127, 1);
display.drawLine(0, 16, 127, 16);
display.setColor(BLACK);
display.fillRect(61,44,16,13); // borro porcentaje
display.setColor(WHITE);
display.drawString(64, 45, String(porcentajeBateria));
display.display();
}
*/