//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <LiquidCrystal_I2C.h>
#define METER_WIDTH 13
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
uint8_t c0[8] = {16,16,16,16,16,0,31};
uint8_t c1[8] = {8,8,8,8,8,0,31};
uint8_t c2[8] = {4,4,4,4,4,0,31};
uint8_t c3[8] = {2,2,2,2,2,0,31};
uint8_t c4[8] = {1,1,1,1,1,0,31};
uint8_t c5[8] = {0,0,0,0,0,0,31};
void meter(int amt, int value)
{
int space;
int position;
int fillspace;
int i=0;
char mstring[20];
if(value > 5 * amt) lcd.print("out of range");
else
{
space = value / 5;
position = 1 + value % 5;
fillspace = amt - space - 1;
if(space)
for(i=0;i < space;i++)
{
mstring[i]='_';
}
mstring[i++]=position;
fillspace += i;
for(i;i<fillspace;i++)
{
mstring[i]='_';
}
}
lcd.print(mstring);
}
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
lcd.createChar(1, c0);
lcd.createChar(2, c1);
lcd.createChar(3, c2);
lcd.createChar(4, c3);
lcd.createChar(5, c4);
lcd.createChar(6, c5);
lcd.setCursor(0,1);
lcd.print(" ");
}
void loop()
{
int j=0;
j=analogRead(A0);
lcd.setCursor(0,0);
lcd.print(j);
lcd.print(" ");
//delay(50);
lcd.setCursor(1,1);
lcd.print("2");
lcd.setCursor(15,1);
lcd.print("3");
lcd.setCursor(2,1);
meter(METER_WIDTH,map(j,0,1024,0,5 * METER_WIDTH));
}