 # Stopwatch with HD44780 LCD?

Hello,

I am trying to make a very simple stopwatch using this code seen here http://www.arduino.cc/en/Tutorial/Stopwatch

and a standard HD44780 LCD. I can get the LCD (in 4-bit mode) and the stopwatch code working perfectly by themselves but cannot figure out a way to combine the two so that the LCD displays the time remaining on the stopwatch.

I am pretty new to arduino coding so any tips would be helpful.

Thank You!

You could try calling function like this in the loop:

void showTime(long elapsedTime){ // routine to report elapsed time int secs = elapsedTime / 1000L ; // divide by 1000 to convert to seconds lcd.printIn(secs); lcd.printIn(".") // print decimal point int fractional = elapsedTime % 1000L; // use modulo operator to get fractional part of time lcd.printIn(fractional); // print fractional part of time }

You will need to position the cursor before each call to the function, you may also need to clear the line.

lcd.printIn(".") // print decimal point
int fractional = elapsedTime % 1000L; // use modulo operator to get fractional part of time
lcd.printIn(fractional); // print fractional part of time

I don’t think this will work quite right unless printIn is smart enough to print the right number of leading zeroes. For example, lets say elapsed time is 1001. In that case, secs = 1001 / 1000 = 1, and fractional = 1001 % 1000 = 1.

I think your code will print this as 1.1 rather than 1.001, but then again I’m not really familiar with the 4-bit LCD library, so I could be wrong.

Also, from an optimization standpoint, you could probably speed things up significantly by replacing the modulus calculation with multiplication and subtraction. I could be wrong about this, but my guess is that (long) % (long) is a fairly complicated calculation (since I know division involving longs is incredibly complicated and hence slow).

int secs = elapsedTime / 1000L; // this is slow but we have to do it
lcd.printIn(secs);
lcd.printIn(".");
int fractional = elapsedTime - secs * 1000L; // I THINK this is much faster than elapsedTime % 1000L
// do something here to figure out how many leading zeroes to first print, eg:
if (fractional < 100)
lcd.printIn(“0”);
else if (fractional < 10)
lcd.printIn(“00”);
lcd.printIn(fractional);

• Ben