Ok Mem, tks for the suggestion. I will try to test that sketch.
What I actually need, is count the time in minutes, since I start a test trip, or a long trip. By the way, how can I reset the program?
I have this sketch, where the if cicles do not work, I don´t know why.
However, the counting of time by assignment of value = millis() is working, cause I have made some test divisions later in the program.
This is my present code:
#include <LiquidCrystal.h>
//create object to control an LCD.
LiquidCrystal lcd(12, 11, 2, 7, 8, 9, 10);
void setup(){
}
void loop(){
float tank;
tank = analogRead(1);
float spend;
float x;
int sec;
int min;
int hour;
unsigned long value; // value states for time in milliseconds
lcd.clear();
value = millis();
if (value == 1000){
sec = sec++; //this doesn´t work
value = 0 ;
}
if(sec==60){
min=min++; // and this either
sec=0;
}
if(min==60) {
hour=hour++; // neither do this
min=0;
}
/* ---------- Prints seconds ------------ */
lcd.setCursor(0,0);
lcd.print("Sec");
lcd.setCursor(5,0);
x = sec;
lcdPrintFloat(x,1);
/* --------- Prints minutes ----------- */
lcd.setCursor(0,1);
lcd.print("Min");
lcd.setCursor(5,1);
x = min;
lcdPrintFloat(x,2);
/* ------- Print Tank values ------- */
lcd.setCursor(8,0);
lcd.print("Tank");
lcd.setCursor(14,0);
x = tank;
lcdPrintFloat(x,1);
/* ------- Print Spend values ------- */
spend = (55-tank)/min;
lcd.setCursor(8,1);
lcd.print("Spend");
lcd.setCursor(14,1);
x = spend;
lcdPrintFloat(x,1);
digitalWrite(13,LOW);
delay (1000); // this is flashing
digitalWrite(13,HIGH);
}
void lcdPrintFloat(float x, byte precision){
lcd.print(long(x));
}