#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//LiquidCrystal_I2C lcd(0x27,20,4); // Define I2C Address where the PCF8574A is
//LiquidCrystal_I2C lcd2(0x26,16,2);
LiquidCrystal_I2C lcd(0x27,16,2);
//#define BACKLIGHT_PIN 3
//#define En_pin 2
//#define Rw_pin 1
//#define Rs_pin 0
//#define D4_pin 4
//#define D5_pin 5
//#define D6_pin 6
//#define D7_pin 7
void setup()
{
lcd.init();
//lcd2.init();
// Switch on the backlight
lcd.setBacklight(HIGH);
//lcd2.setBacklight(HIGH);
//Serial.begin(9600); //2 skärmar
//lcd2.setCursor (2,0);
//lcd2.print ("hi");
lcd.setCursor (2, 0);
lcd.print ("RETR0 GUAGE");
lcd.setCursor (0, 1);
lcd.print ("DEVELOPED BY BSP");
delay(2000);
lcd.clear();
delay(250);
// an0 in
lcd.setCursor (0, 0);
lcd.print ("LAM:");
//delay(50);
// an1 in
lcd.setCursor (0, 1);
lcd.print ("OIL:");
//delay(50);
// an2 in
lcd.setCursor (9, 0);
lcd.print ("MAP:");
//delay(50);
// an3 in
lcd.setCursor (9, 1);
lcd.print ("ECT:");
//delay(250);
}
void loop()
{
byte refreshreate = 1;
lcd.home (); // go home
int an0 = analogRead (A0);
int an1 = analogRead (A1);
int an2 = analogRead (A2);
int an3 = analogRead (A3);
// Analog in 0 kalibrering
an0 = map(an0, 0, 1023, 50, 150);
// Analog in 1 kalibrering
an1 = map(an1, 0, 1023, -400, 1700);
// Analog in 2 kalibrering
an2 = map(an2, 40.92, 982.08, 200, 4000);
// Analog in 3 kalibrering
an3 = map(an3, 0, 1023, -400, 1700);
//float voltage = an1;
//float voltage2 = an3;
lcd.setCursor (4, 0);
lcd.print ((an0) / 100.0,2);//an0
lcd.setCursor(13, 0);
lcd.print ((an2) / 010.0);//an2
lcd.setCursor (4,1);
lcd.print ((an1) / 10.0,0);//an1
lcd.setCursor (13,1);
lcd.print ((an3) / 10.0,0);//an3
lcd.setCursor(7,1);
if (an1 <= -110)
lcd.print("c");
else if (an1 >=1000)
lcd.print ("c");
lcd.setCursor(6,1);
if (an1 >100 and an1 <= 1000)
lcd.print("c ");
else if (an1 <0 and an1 >-90)
lcd.print("c ");
lcd.setCursor(5,1);
if (an1 >0 and an1 <= 101)
lcd.print("c ");
lcd.setCursor(15,1);
if(an3 <= 1000 and an3 >= -110)
lcd.print("c");
}