displaying the result of an operation on an LCD

so I'm using an interrupt to take readings of millis() and subtracting the last reading from the current one to get the interval between button presses. Now i want to put this on an lcd, sending the INT value (or it might be a bigger type) results in goglybook on the screen. How do i transfer from goglybook to readable carachters ?

start with posting your code so we can pinpoint the problem.

#include <LiquidCrystal.h>

volatile unsigned long time1, time2;
volatile int lap;


LiquidCrystal lcd(12, 11, 10, 7, 6, 5, 4);

void setup()
{
  time1 = 0;
  time2 = 0;
  pinMode(2, INPUT);
  digitalWrite(2, HIGH);
  attachInterrupt(0, time, FALLING);
  lcd.begin(16, 2);
  lcd.write(" test");
  lcd.setCursor(1, 1);
  lcd.write("test");
}

void loop() {
 
}

void time()
{
  time2=time1;
  time2 = millis();
  lcd.setCursor(0, 0);
  lap = time2-time1;
  lcd.write(lap);
}

Don't write to the display, print to it. A write sends a (character) code. A print prints a value.

That works now, would be good if the library reference was more explicit.

right thing now is that I'm getting funny numbers, including negative ones and an interval of a second or less produces a 5 digit number rather than 4 digit

You may need to either clear the LCD first, or print an extra space, otherwise a small number will leave parts of the earlier number after it.

Yes I put lcd.clear() in before the code to right the new value but it is not the problem, I’m getting numbers that are definitely not the mS since I last pressed the button and I really can’t see how I could be getting negative numbers unless there is something wrong with my math or assumptions on how the figures will appear on the display. Pressing the button every few seconds seems to get a sensible result but after a few presses it goes haywire.

  time2=time1;
  time2 = millis();

So, time2 is set to equal time1, which has never changed from its initial value of zero, then it is immediately set to the current time.

I think that you meant

  time1=time2;
  time2 = millis();

of course you are right thank you, yes the plan is to shift the last value to time1 so that the last and current time always take the same place in the variables and I can find the time laps with 2-1

working great now, I realised why I was getting negative values, I forgot myself and set the lap variable (the time between readings) to an int so only 30 seconds in and some values fell in the negative roll over. All sorted now with long unsigned.

How can I do things like put a dot before the last 3 digits to show seconds and mS ? I got mS to print after the number so that looks better.

sparkylabs: working great now, I realised why I was getting negative values, I forgot myself and set the lap variable (the time between readings) to an int so only 30 seconds in and some values fell in the negative roll over. All sorted now with long unsigned.

How can I do things like put a dot before the last 3 digits to show seconds and mS ? I got mS to print after the number so that looks better.

I think last few posts of this thread may help?

http://forum.arduino.cc/index.php?topic=175786.0

Looks like they were doing something similar.

How can I do things like put a dot before the last 3 digits to show seconds and mS ? I got mS to print after the number so that looks better.

Try either of these techniques

int lap = 12345  
Serial.print(lap/1000);
  Serial.print(".");
  Serial.println(lap%1000);

  char pBuffer[10];
  int seconds = lap/1000;
  int milliSecs = lap%1000;
  sprintf(pBuffer,"%u.%u",seconds, milliSecs);
  Serial.println(pBuffer);

I tried putting the seconds and milliseconds calculations in the sprintf like this   sprintf(pBuffer,"%u.%u",lap/1000, lap%1000);but get an output of 12.0. Can anyone offer an explanation an/or a method of avoiding the intermediate variables ?

sprintf ?

OK now works great, have got it to "x s x ms"

So how did you do that. Telling about that might educate someone else a bit. Consider that your contribution and thank you to the community for helping out.

MAS3:
So how did you do that.
Telling about that might educate someone else a bit.
Consider that your contribution and thank you to the community for helping out.

Well i used the principles illustrated above but on the lcd instead of serial print, it was the the math i had to get right. by correctly applying the divide and modulo conmands I managed to get the time displayed in minuts, seconds and milli seconds.

#include <LiquidCrystal.h>

volatile unsigned long time1, time2, lap;
volatile int change;

LiquidCrystal lcd(12, 11, 10, 7, 6, 5, 4);

void setup()
{
  time1 = 0;
  time2 = 0;
  pinMode(2, INPUT);
  digitalWrite(2, HIGH);
  attachInterrupt(0, time, FALLING);
  lcd.begin(16, 2);
  lcd.print(" Rotaract  Club");
  lcd.setCursor(1, 1);
  lcd.print("  of Rushden");
  change = 0;
}

void loop() {
  if(change==1){
    lap = time2-time1;
    lcd.clear();
    change = 0;
    time1=time2;
    lcd.setCursor(2, 0);
    lcd.print(lap/1000);
    lcd.write(" s ");
    lcd.print(lap%1000);
    lcd.write(" ms");

    lcd.setCursor(0, 1);
    lcd.print(lap/60000);
    lcd.write(" m ");
    lcd.print(lap%60000/1000);
    lcd.write(" s ");
    lcd.print(lap%1000);
    lcd.write(" ms ");    
  }
}

void time()
{
  time2 = millis();
  change = 1;
}

It won’t make any difference to the operation of your code but making change a boolean variable would make it easier to read as would calling it something different such as newLap and setting it to true in the ISR. You could then use a statement like if (newLap)to test whether it was time to display the lap time.

Did you have a particular reason for using both lcd.write() and lcd.print() ?

Yea i knew there was a better variable for change but got lazy and with all the variables I was making up and then getting rid of the names went a bit haywire.

I used write and print becuase I was unsure and took write to be for writing characters and print for writing results but it looks like write is redundant to me and would be nice if the learning section was updated with more specific information.