Its tricky when one word or just a capital letter can stuff things up, Ive added in some code for my 3rd battery,
This is how it stands so far,
#include <LiquidCrystal.h> //import the Class for the LCD
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //pin numbers for the LCD
const int switchPin = A0; // Select button is connected to pin
const long refreshDelay = 2000; // Duration between display updates
byte oldDisplayMode = 0; // Old display mode
int val; // variable for reading the pin status
int val2; // variable for reading the delayed status
int primary_battPin = 1; // Input from primary Battery
int secondary_battPin = 2; // Input from secondary Battery
int camper_battPin = 3; //Input from camper battery
int primary_val = 0; //temporarily store the primary input
int secondary_val = 0; //temporarily store the secondary input
int camper_val = 0;// //temporarily store the Camper input
float primary_pinVoltage = 0; // variable to hold the calculated voltage
float secondary_pinVoltage = 0; // variable to hold the calculated voltage
float camper_pinVoltage =0; // variable to hold the calculated voltage
float primary_batteryVoltage = 0; //Temporarily store the primary Voltage
float secondary_batteryVoltage = 0; //Temporarily store the secondary Voltage
float camper_batteryVoltage = 0; //Temporarily store the camper Voltage
float ratio = 4.039; // The multiplier depending on which resistors used
// I used 68K and 22K 1/2 watt resistors.
void setup() {
pinMode(switchPin, INPUT); // Set the switch pin as input
lcd.begin(20, 4);
}
void loop(){
long currentTime = millis(); // Get current time
while ((millis() - currentTime) < refreshDelay){
int buttonValue = analogRead(switchPin); // buttonValue should be between 0 and 1023
int displayMode = -1; // Assume no change in display mode
if (buttonValue > 159) {
displayMode = 3;
}
if (buttonValue > 340) {
displayMode = 2;
}
if (buttonValue > 529) {
displayMode = 1;
}
if (buttonValue > 792) {
displayMode = 0;
}
if (displayMode != -1) { // Was button pressed?
if (displayMode != oldDisplayMode) { // Has display mode changed?
oldDisplayMode = displayMode; // Set new display mode
break; // Exit while loop early as button pressed
}
}
}
switch (oldDisplayMode) {
case 0:
lcd.setCursor(0, 0);// Place the Cursor on the Fist line first character position on the LCD screen
lcd.print ("Hello:");// Heading
break;
case 1:
primary_val = analogRead(primary_battPin); //Read the primary Battery input per loop
secondary_val = analogRead(secondary_battPin); //Read the secondary Battery input per loop
camper_val = analogRead(camper_battPin); //Read the Camper Battery input per loop
primary_pinVoltage = primary_val * 0.00488; //0.00488mV per 1024 steps for 5 Volts (ie; 5 / 1024 = 0.00488)
secondary_pinVoltage = secondary_val * 0.00488;
camper_pinVoltage = camper_val * 0.00488;
primary_batteryVoltage = primary_pinVoltage * ratio; //grab the calculated under 5Volt input and multiply it by the ratio to ..........
secondary_batteryVoltage = secondary_pinVoltage * ratio; // .............take it back to the 11~12~13Volt Range.
camper_batteryVoltage = secondary_pinVoltage * ratio;
lcd.setCursor(0, 0);// Place the Cursor on the Fist line first character position on the LCD screen
lcd.print ("Batteries:");// Heading
lcd.setCursor(0, 1); // First Line
lcd.print("Primary : "); // Second Line
lcd.print(primary_batteryVoltage); //The Voltage of Primary Battery.. S
lcd.setCursor(0, 2);// Place the Cursor on the Second line first character position on the LCD screen
lcd.print("Secondary: "); // Third Line
lcd.print(secondary_batteryVoltage); //The Voltage of Secondary Battery.
lcd.setCursor(0, 4); // First Line
lcd.print("Camper : "); // The Voltage of the Battery in the camper.
break;
case 2:
lcd.clear();
lcd.setCursor(0, 0);// Place the Cursor on the Fist line first character position on the LCD screen // Put display mode 1 code here
lcd.print ("temps:");
break;
case 3:
// Put display mode 3 code here
break;
}
}