Count up timer

Hi, i am new to arduino projects.I need help to make a timer counter for arduino uno with lcd 16x2 keypad df robot. I need to view on display four separates counters ( 00:00) only hour and minutes, and to stop reset every counter from keypad. It does not have to be very accurate. I would use it for fishing to conter relative time for every rod. Thank you!

descărcare.jpg

Start by looking up the tutorials in the stickies at the top of this section. You are looking for how to use millis which is explained in the doing multiple things at once tutorials

lcd 16x2 keypad df robot

Is that one of these? If so have you got it working with the test code that shows on the screen that a button is pressed and also shows mills iirc.

Presumably you want one button per rod, and that button will start,stop, reset its rod? If so, what's your thinking for telling the difference between a re-start and a reset? ie if you run for a while and stop it, how does it know the "next press" should start from where it stopped or go back to 0. Or is there no re-start required?

I need help to make...

You don't actually say what "help" you need.

Typically you write a sketch.
Test it
Try to figure out what needs to be changed
Run into a wall
Read HOW TO USE THIS FORUM located at the top of every forum
Post your code as that shows.

Then... we help you figure out what is not working.

I am sorry for poor information postet here. I apologise to you and i will try to be conform with the forum rules. Ok, so i am very novice in this thing, and i am trying to make this project to worg over a month just from self learning. I took a code and i try to multiply the timer sequence and to define buttons but with no result. Do you think is possible to do this? If more parts needed please tell me ,so i will shop them. The code that i use is :

#include <SPI.h>
#include <LiquidCrystal.h>
// these are the pins used on the shield for this sketch
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
// variables used on more than 1 function need to be declared here
unsigned long start, finished, elapsed;
boolean r = false;
// Variables for button debounce time
long lastButtonPressTime = 0; // the last time the button was pressed
long debounceDelay = 50; // the debounce time; keep this as low as possible
void setup()
{
lcd.begin(16, 2); // inicialize the lcd (16 chars, 2 lines)
// a little introduction :slight_smile:
lcd.setCursor(4, 0); // set the cursor to first character on line 1 - NOT needed (it sets automatically on lcd.begin()
lcd.print(“Arduino”);
lcd.setCursor(3, 1); // set the cursor to 4th character on line 2
lcd.print(“StopWatch”);
delay(2000);
lcd.clear();
lcd.print(“Press select for”);
lcd.setCursor(2, 1); // set the cursor to 3rd character on line 2
lcd.print(“Start & Stop”);
}
void loop()
{
CheckStartStop();
DisplayResult();
}
void CheckStartStop()
{
int x = analogRead (0); // assign ‘x’ to the Arduino’s AnalogueInputs (Shield’s buttons)
if (x < 800 && x > 600 ) // if the button is SELECT
{
if ((millis() - lastButtonPressTime) > debounceDelay)
{
if (r == false)
{
lcd.clear();
lcd.setCursor(3, 0); // needed
lcd.print(“Time Past”);
start = millis(); // saves start time to calculate the elapsed time
}
else if (r == true)
{
lcd.setCursor(2, 0); // needed
lcd.print(" Final Time ");
}
r = !r;
}
lastButtonPressTime = millis();
}
}
void DisplayResult()
{
if (r == true)
{
finished = millis(); // saves stop time to calculate the elapsed time
// declare variables
float h, m, s, ms;
unsigned long over;
// MATH time!!!
elapsed = finished - start;
h = int(elapsed / 3600000);
over = elapsed % 3600000;
m = int(over / 60000);
over = over % 60000;
s = int(over / 1000);
ms = over % 1000;
// display the results
lcd.setCursor(0, 1);
lcd.print(h, 0); // display variable ‘h’ - the 0 after it is the number of algorithms after a comma (ex: lcd.print(h, 2); would print 0,00
lcd.print("h "); // and the letter ‘h’ after it
lcd.print(m, 0);
lcd.print("m ");
lcd.print(s, 0);
lcd.print("s ");
if (h < 10)
{
lcd.print(ms, 0);
lcd.print("ms ");
}
}
}

Unfortunately,i do not save any sketch. In the button/ command problem the 4 buttons should do only reset counter.
Again i am verry sorry for the first post.
Many thanks and all the best!

Have a look at the guide at the top. You need to post your code in code tags otherwise you get :slight_smile: etc and people can’t read it easily

Here’s op’s code control-t’d and tagged:

#include <SPI.h>
#include <LiquidCrystal.h>
// these are the pins used on the shield for this sketch
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
// variables used on more than 1 function need to be declared here
unsigned long start, finished, elapsed;
boolean r = false;
// Variables for button debounce time
long lastButtonPressTime = 0; // the last time the button was pressed
long debounceDelay = 50; // the debounce time; keep this as low as possible

void setup()
{
  lcd.begin(16, 2); // inicialize the lcd (16 chars, 2 lines)
  // a little introduction :)
  lcd.setCursor(4, 0); // set the cursor to first character on line 1 - NOT needed (it sets automatically on lcd.begin()
  lcd.print("Arduino");
  lcd.setCursor(3, 1); // set the cursor to 4th character on line 2
  lcd.print("StopWatch");
  delay(2000);
  lcd.clear();
  lcd.print("Press select for");
  lcd.setCursor(2, 1); // set the cursor to 3rd character on line 2
  lcd.print("Start & Stop");
}//setup

void loop()
{
  CheckStartStop();
  DisplayResult();
}//loop

void CheckStartStop()
{
  int x = analogRead (0); // assign 'x' to the Arduino's AnalogueInputs (Shield's buttons)
  if (x < 800 && x > 600 ) // if the button is SELECT
  {
    if ((millis() - lastButtonPressTime) > debounceDelay)
    {
      if (r == false)
      {
        lcd.clear();
        lcd.setCursor(3, 0); // needed
        lcd.print("Time Past");
        start = millis(); // saves start time to calculate the elapsed time
      }
      else if (r == true)
      {
        lcd.setCursor(2, 0); // needed
        lcd.print(" Final Time ");
      }
      r = !r;
    }
    lastButtonPressTime = millis();
  }
}//CheckStartStop

void DisplayResult()
{
  if (r == true)
  {
    finished = millis(); // saves stop time to calculate the elapsed time
    // declare variables
    float h, m, s, ms;
    unsigned long over;
    // MATH time!!!
    elapsed = finished - start;
    h = int(elapsed / 3600000);
    over = elapsed % 3600000;
    m = int(over / 60000);
    over = over % 60000;
    s = int(over / 1000);
    ms = over % 1000;
    // display the results
    lcd.setCursor(0, 1);
    lcd.print(h, 0); // display variable 'h' - the 0 after it is the number of algorithms after a comma (ex: lcd.print(h, 2); would print 0,00
    lcd.print("h "); // and the letter 'h' after it
    lcd.print(m, 0);
    lcd.print("m ");
    lcd.print(s, 0);
    lcd.print("s ");
    if (h < 10)
    {
      lcd.print(ms, 0);
      lcd.print("ms ");
    }
  }
}//DisplayResult

r is a poor name for a variable. Give it a proper name that means something relevant

Please tell us what you want to do.
Something like

I have 4 fishing poles.
I want to cast a line and press a button
Then do that for the other 3 poles.

5 minutes after i press the button.
I want the display to say pole 2 and nuzz the nuzzer.
I will cast pole 2 and press ththe button for pole 2 ant the timer will start again

OK,the timer should work like this: first display 4 time counters for each rod, each timer has to count independant, 4 buttons to reset each counter, after pushing button the counter corespondant satrt again from 00:00 withdeauth affecting others 3, and display only hh:mm for every rod. The original one that i put pictures does the same, i guess it is build with pic controller, the problem is that i do not have from who to borrow one to see how it is made. i have looked for schematic and code for pic but nothing. One of my coleague from work said that it could be made with arduino, but we are stuck( he knows arduino a lot more than me and a lot less than you). Maybe this counter does not work with arduino uno and works with arduino mega,maybe requres a clock shield,maybe the code that we try to mody fy it is not good for this, we do not know so i have asked for help here maybe someone could guide me what to do.
Many thanks !

You didn't answer my question asking for confirmation on the shield type, but the code you have seems to be for one of those. Have you run the test code for that shield, and do you understand how to read the buttons, which are all on the same analog pin. Do that first and understand your own hardware.

The simplest approach, but it's pretty ugly, is to reproduce the function CheckStartStop() and have 4 of them, CheckStartStop1() etc. Call all of them from loop(). Change each to work a different button, assuming you understand how that hardware and its test code do read the buttons on the same analog pin. That will involved using different variables in each of course. And the boolean "r" which is presumably "running" would need duplication as "running1" "running2" etc. Then upgrade the display function to update all the counters on the display together.

i have asked for help here maybe someone could guide me what to do.

It's difficult to "guide" any more than I already said. Next level of guiding would be pseudocode and if anyone does that they might as well write the actual code for you. What level of guidance do you need?- working code from someone?

I'm wondering why the code you posted calls for the SPI library, since it's not needed for the shield itself and I don't see anything in the code that uses it. Presumably that code was lifted from a bigger project, that might have used an SD card or something?

Yes the lcd shield is the one you mentioned,the code it was downloaded from internet ( i have searcing projects that inlude lcd ,arduino and timer,countdown,upcounter,fitness counter,multiple timers,cooking timers,etc.). i do not know if the original project that used this code needed SD card. I do not want to ask someone else to waste his time and knowledge to write a code for me( it is not fair for you and for everybody on this forum if is not payd or rewarded somehow). My profession is HVAC Senior Tehnician most on sevice department for about 15 years, i have some electronic and electric knowledges,but this is my first time arduino project and my first interracion with this kind of things. I want to learn and do other projects for my kids. I will try to do what you said and i will keep you posted.
Many thanks!

[cod

 #include <SPI.h>  
 #include <LiquidCrystal.h>  
 // these are the pins used on the shield for this sketch  
 LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);  
 // variables used on more than 1 function need to be declared here  
 unsigned long start , finished, elapsed;  
 boolean running1 = false; 
 boolean running2 = false; 
 // Variables for button debounce time  
 long lastButtonPressTime = 0; // the last time the button was pressed  
 long debounceDelay = 50; // the debounce time; keep this as low as possible  
 void setup()  
 {  
 lcd.begin(16, 2); // inicialize the lcd (16 chars, 2 lines)  
 // a little introduction :)  
 lcd.setCursor(4, 0); // set the cursor to first character on line 1 - NOT needed (it sets automatically on lcd.begin()  
 lcd.print("Arduino");  
 lcd.setCursor(3, 1); // set the cursor to 4th character on line 2  
 lcd.print("StopWatch");  
 delay(2000);  
 lcd.clear();  
 lcd.print("Press select for");  
 lcd.setCursor(2, 1); // set the cursor to 3rd character on line 2  
 lcd.print("Start & Stop");  
 }  
 void loop()  
 {  
 CheckStartStop1();  
 DisplayResult();  
 }  
 void CheckStartStop1()
 void CheckStartStop2()  
 {  
 int x = analogRead (0); // assign 'x' to the Arduino's AnalogueInputs (Shield's buttons)  
 if (x < 800 && x > 600 ) // if the button is SELECT  
 
 {  
 if ((millis() - lastButtonPressTime) > debounceDelay)  
 {  
 if (running1 == false)  
 {  
 lcd.clear();  
 lcd.setCursor(3, 0); // needed  
 lcd.print("Time Past");  
 start = millis(); // saves start time to calculate the elapsed time  
 }  
 else if (running1 == true)  
 {  
 lcd.setCursor(2, 0); // needed  
 lcd.print(" Final Time ");  
 }  
 running1 = !running1;  
 }  
 lastButtonPressTime = millis();  
 }  
 }  
 void DisplayResult()  
 {  
 if (running1 == true)  
 {  
 finished = millis(); // saves stop time to calculate the elapsed time  
 // declare variables  
 float h, m, s, ms;  
 unsigned long over;  
//  CheckStartStop1();  
  DisplayResult();  
  {
  
   {
 int x = analogRead (0); // assign 'x' to the Arduino's AnalogueInputs (Shield's buttons)  
 if (x < 400 && x > 200 ) // if the button is SELECT  
 
 {  
 if ((millis() - lastButtonPressTime) > debounceDelay)  
 {  
 if (running2 == false)  
 {  
 lcd.clear();  
 lcd.setCursor(3, 0); // needed  
 lcd.print("Time Past");  
 start = millis(); // saves start time to calculate the elapsed time  
 }  
 else if (running2 == true)  
 {  
 lcd.setCursor(2, 0); // needed  
 lcd.print(" Final Time ");  
 }  
 running2 = !running2;  
 }  
 lastButtonPressTime = millis();  
 }  
 }  
 void DisplayResult()  
 
 if (running2 == true)  
 {  
 finished = millis(); // saves stop time to calculate the elapsed time  
 // declare variables  
 float h, m, s, ms;  
 unsigned long over;  
 // MATH time!!!  
 elapsed = finished - start;  
 h = int(elapsed / 3600000);  
 over = elapsed % 3600000;  
 m = int(over / 60000);  
 over = over % 60000;  
 s = int(over / 1000);  
 ms = over % 1000;  
 // display the results  
 lcd.setCursor(0, 0);  
 lcd.print(h, 0); // display variable 'h' - the 0 after it is the number of algorithms after a comma (ex: lcd.print(h, 2); would print 0,00  
 lcd.print("h "); // and the letter 'h' after it  
 lcd.print(m, 0);  
 lcd.print("m ");  
 lcd.print(s, 0);  
 lcd.print("s ");  
 if (h < 10)  
 {  
 //lcd.print(ms, 0);  
 //lcd.print("ms ");  
 }  
  lcd.setCursor(8, 0);  
 lcd.print(h, 0); // display variable 'h' - the 0 after it is the number of algorithms after a comma (ex: lcd.print(h, 2); would print 0,00  
 lcd.print("h "); // and the letter 'h' after it  
 lcd.print(m, 0);  
 lcd.print("m ");  
 lcd.print(s, 0);  
 lcd.print("s ");  
 if (h < 10)  
 {  
 //lcd.print(ms, 0);  
 //lcd.print("ms ");  
 }  
  lcd.setCursor(0, 1);  
 lcd.print(h, 0); // display variable 'h' - the 0 after it is the number of algorithms after a comma (ex: lcd.print(h, 2); would print 0,00  
 lcd.print("h "); // and the letter 'h' after it  
 lcd.print(m, 0);  
 lcd.print("m ");  
 lcd.print(s, 0);  
 lcd.print("s ");  
 if (h < 10)  
 {  
 //lcd.print(ms, 0);  
 //lcd.print("ms ");  
 } 
  lcd.setCursor(8, 1);  
 lcd.print(h, 0); // display variable 'h' - the 0 after it is the number of algorithms after a comma (ex: lcd.print(h, 2); would print 0,00  
 lcd.print("h "); // and the letter 'h' after it  
 lcd.print(m, 0);  
 lcd.print("m ");  
 lcd.print(s, 0);  
 lcd.print("s ");  
 if (h < 10)  
 {  
 //lcd.print(ms, 0);  
 //lcd.print("ms ");  
 }   
 }  
 }

e][/code]

I just succeded to multiply the counter to show 4 times, but they work as one. I olso tested the other buttons and they work. I tryied to do what you say about function but i do not know how.

I had a rethink, and went about it differently from the way I suggested in #10. I went back to the code DFR post on the product page, which displays which button is currently pressed. Of course, we don't want to know which button is pressed, we want to know which one just became pressed: so I incorporated a variable lcd_key_prev to let me see that a new button was pressed. (It's handy that they already have a btnNONE, so this essentially boils down to if btnRIGHT/LEFT/DOWN/UP is currently pressed and the previous read was btnNONE, we know which button is a new press. )

Then I changed the sketch so that it only goes into the switch...case on a new press, and in each case toggled a variable running0, running1* etc.

In a display function, I display 4 values. A rod's value is either the elapsed time if running, or 0 if not.

It's difficult to describe any more than that without posting my actual code: if you want it I'll post it.

*Yes I know it will benefit from the use of arrays. Perhaps that will be v2, or "left as an exercise for the reader".

It would be a very big help if you would post the code.
Many thanks!

Try this. I’ll leave it to you to convert the seconds to hms or whatever.

// https://forum.arduino.cc/index.php?topic=703444.0
// 4 timers 0-3, each started/stopped by a button r/u/d/l
// ***** THIS VERSION WILL BENEFIT FROM CONVERSION TO ARRAYS ;) *****

// based on code at https://wiki.dfrobot.com/Arduino_LCD_KeyPad_Shield__SKU__DFR0009_

//Sample using LiquidCrystal library
#include <LiquidCrystal.h>

/*******************************************************
  This program will test the LCD panel and the buttons
  Mark Bramwell, July 2010

  This version checks for a **NEW** press  September 2020 vilmabergmann
********************************************************/

// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// define some values used by the panel and buttons
byte lcd_key;
byte lcd_key_prev;
int adc_key_in  = 0; //needs to hold an analog read
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

bool running0 = false; //one day these will be in an array ;)
bool running1 = false;
bool running2 = false;
bool running3 = false;

unsigned long millis0; //one day these will be in an array ;)
unsigned long millis1;
unsigned long millis2;
unsigned long millis3;

unsigned long start0; //one day these will be in an array ;)
unsigned long start1;
unsigned long start2;
unsigned long start3;

void setup()
{
  Serial.begin(9600);
  lcd_key = read_LCD_buttons();
  lcd_key_prev = lcd_key;
  lcd.begin(16, 2);              // start the library
  lcd.setCursor(0, 0);
  lcd.print("Push the buttons"); // print a simple message
  lcd.setCursor(0, 1);
  lcd.print("   R U D or L");
  delay(1000);
  lcd.clear();
  Serial.println("setup() done");
}//setup

void loop()
{
  showRods();
  startStopRods();
}//loop

void showRods()
{
  lcd.setCursor(0, 0);
  if (running0) lcd.print((millis() - start0) / 1000); else lcd.print("0");
  lcd.setCursor(8, 0);
  if (running1) lcd.print((millis() - start1) / 1000); else lcd.print("0");
  lcd.setCursor(0, 1);
  if (running2) lcd.print((millis() - start2) / 1000); else lcd.print("0");
  lcd.setCursor(8, 1);
  if (running3) lcd.print((millis() - start3) / 1000); else lcd.print("0");
}//showRods

void startStopRods()
{
  lcd.setCursor(0, 1);           // move to the begining of the second line
  lcd_key = read_LCD_buttons();  // read the buttons
  if (lcd_key != lcd_key_prev) // ***so only goes into the switch if there's a new press or release***
  {
    switch (lcd_key)               // depending on which button x was newly pushed, we toggle runningx
    {
      case btnRIGHT: //0
        {
          lcd.setCursor(0, 0);
          lcd.print("        "); //clear its part of the display
          running0 = !running0;
          if (running0)
          {
            start0 = millis();
          }
          Serial.println("new right");
          break;
        }
      case btnLEFT://3
        {
          lcd.setCursor(8, 1);
          lcd.print("        "); //clear its part of the display
          running3 = !running3;
          if (running3)
          {
            start3 = millis();
          }

          Serial.println("new left");
          break;
        }
      case btnUP://1
        {
          lcd.setCursor(8, 0);
          lcd.print("        "); //clear its part of the display
          running1 = !running1;
          if (running1)
          {
            start1 = millis();
          }
          Serial.println("new up");
          break;
        }
      case btnDOWN://2
        {
          lcd.setCursor(0, 1);
          lcd.print("        "); //clear its part of the display
          running2 = !running2;
          if (running2)
          {
            start2 = millis();
          }
          Serial.println("new down");
          break;
        }
        /*
          case btnSELECT://4
          {
          //lcd.print("SELECT");
          Serial.print("new select");
          break;
          }

          case btnNONE://5
          {
          //lcd.print("NONE  ");
          Serial.println(", released");
          break;
          }
        */

    }//switch
    delay(50); //poor man's debounce
  }
  lcd_key_prev = lcd_key;
}//startStopRods

// read the buttons
int read_LCD_buttons()
{
  adc_key_in = analogRead(0);      // read the value from the sensor
  // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
  // we add approx 50 to those values and check to see if we are close
  if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
  // For V1.1 us this threshold
  if (adc_key_in < 50)   return btnRIGHT;
  if (adc_key_in < 250)  return btnUP;
  if (adc_key_in < 450)  return btnDOWN;
  if (adc_key_in < 650)  return btnLEFT;
  if (adc_key_in < 850)  return btnSELECT;

  // For V1.0 comment the other threshold and use the one below:
  /*
    if (adc_key_in < 50)   return btnRIGHT;
    if (adc_key_in < 195)  return btnUP;
    if (adc_key_in < 380)  return btnDOWN;
    if (adc_key_in < 555)  return btnLEFT;
    if (adc_key_in < 790)  return btnSELECT;
  */


  return btnNONE;  // when all others fail, return this...
}//read_LCD_buttons

Hi to all. I will post the finnised code here. Many , many thanks for your support!

// https://forum.arduino.cc/index.php?topic=703444.0
// 4 timers 0-3, each started/stopped by a button r/u/d/l
// ***** THIS VERSION WILL BENEFIT FROM CONVERSION TO ARRAYS ;) *****

// based on code at https://wiki.dfrobot.com/Arduino_LCD_KeyPad_Shield__SKU__DFR0009_

//Sample using LiquidCrystal library
#include <LiquidCrystal.h>

/*******************************************************
  This program will test the LCD panel and the buttons
  Mark Bramwell, July 2010

  This version checks for a **NEW** press  September 2020 vilmabergmann
********************************************************/

// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

// define some values used by the panel and buttons
byte lcd_key;
byte lcd_key_prev;
int adc_key_in  = 0; //needs to hold an analog read
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

bool running0 = false; //one day these will be in an array ;)
bool running1 = false;
bool running2 = false;
bool running3 = false;

unsigned long millis0; //one day these will be in an array ;)
unsigned long millis1;
unsigned long millis2;
unsigned long millis3;

unsigned long start0; //one day these will be in an array ;)
unsigned long start1;
unsigned long start2;
unsigned long start3;

unsigned long t_ore = 0;
unsigned long t_minute = 0;
unsigned long t_secunde = 0;


void setup()
{
  Serial.begin(9600);
  lcd_key = read_LCD_buttons();
  lcd_key_prev = lcd_key;
  lcd.begin(16, 2);              // start the library
  lcd.setCursor(0, 0);
  lcd.print("Push the buttons"); // print a simple message
  lcd.setCursor(0, 1);
  lcd.print("   R U D or L");
  delay(1000);
  lcd.clear();
  Serial.println("setup() done");
}//setup

String AfisareMiki(unsigned long diff_milisecunde)
{
  t_ore = (millis() - diff_milisecunde) / 3600000;
  t_minute = (millis() - diff_milisecunde - t_ore * 3600000) / 60000;
  t_secunde = (millis() - diff_milisecunde - t_ore * 3600000 - t_minute * 60000) / 1000;

  String s_ore = String(t_ore);
  if (s_ore == "")
  {
    t_ore = 0;
    s_ore = "00";
  }
  String s_minute = String(t_minute);
  if (s_minute == "")
  {
    t_minute = 0;
    s_minute = "00";
  }
  String s_secunde = String(t_secunde);
  if (s_secunde == "")
  {
    t_secunde = 0;
    s_secunde = "00";
  }

  String timp;

  //timp = s_ore+":"+s_minute+":"+s_secunde;
  timp = s_ore+":"+s_minute;
  return timp;
}

void loop()
{
  //AfisareMiki(123);
  //delay(1000);
  showRods();
  startStopRods();
}//loop


void showRods()
{
  lcd.setCursor(0, 0);
  if (running0)
  {
    lcd.print("1- ");
    lcd.print(AfisareMiki(start0));
    //lcd.print((millis() - start0) / 1000);
  }
  else lcd.print("0");
 
  lcd.setCursor(9, 0);
  if (running1)
  {
    lcd.print("2- ");
    lcd.print(AfisareMiki(start1));
    //lcd.print((millis() - start0) / 1000);
  }
  else lcd.print("0");
 
  lcd.setCursor(0, 1);
  if (running2)
  {
    lcd.print("3- ");
    lcd.print(AfisareMiki(start2));
    //lcd.print((millis() - start0) / 1000);
  }
  else lcd.print("0");

  lcd.setCursor(9, 1);
  if (running3)
  {
    lcd.print("4- ");
    lcd.print(AfisareMiki(start3));
    //lcd.print((millis() - start0) / 1000);
  }
  else lcd.print("0");
}//showRods



void startStopRods()
{
  lcd.setCursor(0, 1);           // move to the begining of the second line
  lcd_key = read_LCD_buttons();  // read the buttons
  if (lcd_key != lcd_key_prev) // ***so only goes into the switch if there's a new press or release***
  {
    switch (lcd_key)               // depending on which button x was newly pushed, we toggle runningx
    {
      case btnLEFT: //0
        {
          lcd.setCursor(0, 0);
          lcd.print("        "); //clear its part of the display
          running0 = !running0;
          if (running0)
          {
            start0 = millis();
          }
          Serial.println("new right");
          break;
        }
      case btnRIGHT://3
        {
          lcd.setCursor(9, 1);
          lcd.print("        "); //clear its part of the display
          running3 = !running3;
          if (running3)
          {
            start3 = millis();
          }

          Serial.println("new left");
          break;
        }
      case btnUP://1
        {
          lcd.setCursor(9, 0);
          lcd.print("        "); //clear its part of the display
          running1 = !running1;
          if (running1)
          {
            start1 = millis();
          }
          Serial.println("new up");
          break;
        }
      case btnDOWN://2
        {
          lcd.setCursor(0, 1);
          lcd.print("        "); //clear its part of the display
          running2 = !running2;
          if (running2)
          {
            start2 = millis();
          }
          Serial.println("new down");
          break;
        }
        /*
          case btnSELECT://4
          {
          //lcd.print("SELECT");
          Serial.print("new select");
          break;
          }

          case btnNONE://5
          {
          //lcd.print("NONE  ");
          Serial.println(", released");
          break;
          }
        */

    }//switch
    delay(50); //poor man's debounce
  }
  lcd_key_prev = lcd_key;
}//startStopRods

// read the buttons
int read_LCD_buttons()
{
  adc_key_in = analogRead(0);      // read the value from the sensor
  // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
  // we add approx 50 to those values and check to see if we are close
  if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
  // For V1.1 us this threshold
  if (adc_key_in < 50)   return btnRIGHT;
  if (adc_key_in < 200)  return btnUP;
  if (adc_key_in < 400)  return btnDOWN;
  if (adc_key_in < 600)  return btnLEFT;
  if (adc_key_in < 800)  return btnSELECT;

  // For V1.0 comment the other threshold and use the one below:
  /*
    if (adc_key_in < 50)   return btnRIGHT;
    if (adc_key_in < 195)  return btnUP;
    if (adc_key_in < 380)  return btnDOWN;
    if (adc_key_in < 555)  return btnLEFT;
    if (adc_key_in < 790)  return btnSELECT;
  */


  return btnNONE;  // when all others fail, return this...
}//read_LCD_buttons