#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);
int batteryPin = A0;
int batteryLevel = 0;
char buf[9];
void setup(void) {
pinMode(batteryPin, INPUT);
Serial.begin(9600);
u8g.setFont(u8g_font_gdr30r);
}
void loop(void) {
int potValue = analogRead(batteryPin);
batteryLevel = map(potValue, 0, 1023, 0, 12);
u8g.firstPage();
do{
sprintf (buf, "%d", batteryLevel);
u8g.drawStr(70,50,buf);
u8g.drawFrame(20,12,40,50);
u8g.drawFrame(30,10,20,3);
if(potValue>20){
u8g.setColorIndex(1);
u8g.drawBox(22, 50, 35,10);
}
if(batteryLevel>3){
u8g.setColorIndex(1);
u8g.drawBox(22, 38, 35,10);
}
if(batteryLevel>6){
u8g.setColorIndex(1);
u8g.drawBox(22, 26, 35,10);
}
if(batteryLevel>8){
u8g.setColorIndex(1);
u8g.drawBox(22, 14, 35,10);
}
}while( u8g.nextPage() );
}