#include <OneWire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#include "LcdBarGraphRobojax.h"
// Data wire is plugged into port 7 on the Arduino
#define ONE_WIRE_BUS 7
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
const int offset = 20;
const int sensor_max = 2500;
const double voltage_to_measure = 12.8;
byte lcdNumCols = 16; // -- number of columns in the LCD
byte lcdLine = 2; // -- number of line in the LCD
LiquidCrystal_I2C lcd(0x27, 16, 2); // -- creating LCD instance
LcdBarGraphRobojax lbg(&lcd, 16, 0, 0); // -- creating 16 character long bargraph starting at char 0 of line 0
void setup(){
Serial.begin(9600);
sensors.begin();
// -- initializing the LCD
lcd.begin(lcdNumCols, lcdLine);
lcd.clear();
lcd.print("Voltagem Bateria");
lcd.setCursor (0,1); //
lcd.print("Temperatura Carga");
delay(2000);
lcd.clear();
}
void loop()
{
sensors.requestTemperatures();
int tempC = sensors.getTempCByIndex(0);
int inpuValue0 = analogRead(A0);
int volt0 = analogRead(A0);
double voltage0 = map(volt0, 0, 1023, 0, sensor_max) + offset;// map 0-1023 to 0-2500 and add correction offset
double voltage_0 = voltage0 / 100;
voltage0 /= voltage_to_measure;// divide by 100 to get the decimal values
lbg.clearLine(1);// clear line 1 to display fresh voltage value
// -- draw bar graph from the analog value read
lbg.drawValue(inpuValue0, 520);
// -- do some delay: frequent draw may cause broken visualization
lcd.setCursor (0, 1); //
lcd.print(voltage_0);
lcd.setCursor (4, 1);
lcd.print("V");
lcd.setCursor (6, 1);
lcd.print(tempC);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor (11, 1);
lcd.print(voltage0);
lcd.setCursor (15, 1);
lcd.print("%");
delay(100);
}