Hi.
Ive been building this battery monitor and has it working and running well. PCB's printed and a few out for testing.
For now, the code is such that battery capacity, Low volts, High Volts and LCD brightness has to be entered into the code part.
I would like to move it out of the code and into a simple menu.
The menu option should be visible during the first 5 seconds after a reset and entered into if a button is pushed during these 5 seconds.
Secondly, once inside the menu i would like to be able to jump inbetween the parameters with that same menu button which is conected to pin9.
On a specific item of the menu such as "battery capacity" the other 2 buttons which are on A4 and A5 should be able to add 1 or substract one from these values. When Menu is then pressed it should save the value into the EEPROM and move to the next menu item until it reaches the end of the menu.
Once it goes out the setup() routine and completes the menu it should run in the main code.
Currently the main code has the menu button in such a way that if its pushed it jumpes between the different screens on the LCD. All i want to add here is that if the menu button is pushed, it should jump to next screen(as now) and if its held down for longer than about 2s it should reset the value of that screen.
Examples of values to be reset would be Max volts, Max Amps in, Max Amps out, AH in, Ah out.
What would be the most feasable way to go forward provided that I dont want to change hardware and having the code working really well as below attached?
Any help or advice would be appreciated.
#include <LiquidCrystal.h>
//______________________________________________________________________________________
float capacity = 7; //This value of 7aH must be changed for the size battery you have. |
float chargeefficiency =0.85; //This value can be changed based on type of battery/charger|
float lowvolts = 11.3; //Pick the volts that relay should switch off
float highvolts = 12.2; //Pick the volts that the relay should switch on
int backlightbrightness = 70;//0 backlight off to 255 Backlight at its brightest
//**************************************************************************************|
*************************************************************************************|
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = 0; // current state of the button
int lastButtonState = 0; // previous state of the button
long previousMillis = 0;
long interval = 500; // interval at which to update screens
unsigned long currentMillis =0;
//==========================================================================================
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //dont worry about this, LCD stuff
void setup() {
pinMode(menubuttonPin, INPUT);
pinMode(relaypin, OUTPUT);
pinMode(lcdbacklightpin,OUTPUT);
digitalWrite(relaypin,HIGH);
digitalWrite(lcdbacklightpin,HIGH);
relaycondition = true;
lcd.begin(16, 2); //This is the first bit to be displayed when the unit is
//this will show which code version is loaded
tone(buzzer,500,1500); //compare it with the one on the forum
delay(5000);
lcd.clear();
lcd.setCursor(2,0);
lcd.print("CHARGE = C "); //powered up. It shows if you have the size battery
lcd.setCursor(2,1); //correct in the top line of the code.
lcd.print("LOAD = L");
delay(5000);
lcd.clear();
}
//------------------------------------Main Program-------------------------------------
void loop() {
analogWrite(lcdbacklightpin,backlightbrightness);
volts = getvolts();
ampin = getampin();
ampout = getampout();
percent = getcalcpercentage(volts);
amphoursleftreading = getamphoursleft(percent);
if(millis()>50000) //Allow voltage to settle on startup before looking to switch relay off
{
dorelay(volts);
}
if (buttonState != lastButtonState) // compare the buttonState to its previous state
{
lcd.setCursor(0,1);
lcd.print(" ");
delay(50); // if the state has changed, increment the counter
if (buttonState == HIGH)
{
buttonPushCounter++; // if the current state is HIGH then the button changed
if(buttonPushCounter==8)
{
buttonPushCounter=0;
}
}
}
lastButtonState = buttonState; // save the current state as the last state,
currentMillis = millis();
if(currentMillis - previousMillis > interval)
{
previousMillis = currentMillis; //for next time through the loop
lcd.setCursor(0, 0); //Start of the first line of the LCD
lcd.print(volts,2);
lcd.print("v");
if(percent<20) {
lcd.print(" LOW "); //This is when battery is low
tone(buzzer,1500,200);
}
else if(percent>100){
lcd.print(" CHARGING "); //This will tell you if you are charging the battery
}
else
{
lcd.print("/");
lcd.print(percent,0);
lcd.print("%/");
}
lcd.print(amphoursleftreading,0);
lcd.print("Ah "); //End of the first line of the LCD
lcd.print(buttonPushCounter);
lcd.setCursor(0,1); //Start of the second line of the LCD
if(buttonPushCounter==0)
{
lcd.print("C ");
lcd.print(ampin,1);
lcd.print("A ");
lcd.print("L ");
lcd.print(ampout,1);
lcd.print("A ");
}
if(buttonPushCounter==1)
{
lcd.print("C ");
lcd.print(amphoursinreading,1);
lcd.print("Ah ");
lcd.print("L ");
lcd.print(amphoursoutreading,1);
lcd.print("Ah ");
}
if(buttonPushCounter==2)
{
lcd.print("Est Hours ");
lcd.print(timeah);
lcd.print(" ");
}
if(buttonPushCounter==3)
{
lcd.print("Max Volts ");
lcd.print(maxvolts,2);
lcd.print("v ");
}
if(buttonPushCounter==4)
{
lcd.print("Max A in ");
lcd.print(maxampin,1);
lcd.print("A ");
}
if(buttonPushCounter==5)
{
lcd.print("Max A out ");
lcd.print(maxampout,1);
lcd.print("A ");
}
if(buttonPushCounter==6)
{
lcd.print("Balance ");
if(amphoursbalance>0)
{
lcd.print("+");
}
lcd.print(amphoursbalance,1);
lcd.print("Ah ");
}
if(buttonPushCounter == 7)
{
if(relaycondition ==true)
{
lcd.print("Relay On ");
}
else
if(relaycondition ==false)
{
lcd.print("Relay Off ");
}
}
}
}
//----------------------------New Subroutines---------------------------
//Removed due to forum count