Original is here:
http://forum.arduino.cc/index.php?topic=182167.0
just updated my little project a little, both hardware and software, any suggestion will be great!!
#include <LiquidCrystal.h>
LiquidCrystal lcd(8,9,10,11,12,13);
/*
int leds[8]={0,1,2,3,4,5,6,7};
int Vohm[2]={A0,A1};
int Button[4]={A2,A3,A4,A5};*/
int sec=0;
int minu=0;
int hr=0;
unsigned long time=0;
unsigned long pstimer=0;
float DV=0;
float BV=1;
int ma=0;
float mah=0;
float mahnow=0;
int timerx=1;
//========================================================================================================================
void setup() {
lcd.begin(16,2);
pinMode (7, OUTPUT);
pinMode (5, OUTPUT);
pinMode (3, OUTPUT);
pinMode (A2, INPUT); // battery voltage
pinMode (A5, INPUT);// resistor drop voltage
pinMode (A3, INPUT); //Display changing button
digitalWrite (7,HIGH);
digitalWrite (5,HIGH);
digitalWrite (3,HIGH);
}
//========================================================================================================================
void loop() {
if(BV<0.1){
digitalWrite (7,LOW);
digitalWrite (5,LOW);
digitalWrite (3,LOW);
timerx=0;
}
unsigned long timer= millis();
if(timer-pstimer > 1000){
sec++;
float BV1 = analogRead(A2);
BV = BV1/1023*5.18; // compensate for resistor, need to check for the real volt and the volt from the arduino are the same!
float DV1 = analogRead(A5);
DV = DV1/1023*4.98; // check the 5V arduino to ground. Usually, it's less than 5 volts.
ma=DV*1000;
mahnow=DV/3.6;
if (BV>0.1){
mah=mah+mahnow;}
lcd.setCursor(0,0);
lcd.print( " " );
pstimer = timer;
}
if(sec==60){
sec=0;
if (timerx==1){
minu++;}
}
if(minu==60){
minu=0;
hr++;
}
//================================Time and mah
char szTime[8];
sprintf( szTime, "T%02d:%02d", hr, minu );
lcd.setCursor(0,0);
lcd.print( szTime );
lcd.setCursor(7,0);
lcd.print(mah);
lcd.setCursor(13,0);
lcd.print("Mah");
//================================Batttery volt and current in ma
lcd.setCursor(0,1);
lcd.print("B:");
lcd.setCursor(1,1);
lcd.print(BV);
lcd.setCursor(5,1);
lcd.print("V");
char maC[6];
sprintf (maC, "%04d Ma",ma);
lcd.setCursor(7,1);
lcd.print(maC);
}