1
votes

I am trying to create a basic arduino uno stopwatch displayed on a liquid crystal display. In theory , this is a very easy project, yet I am running into issues with my display. I calculate my minutes and seconds, and then attempt to print them to the display with a colon in between. Coming from java, I presumed a plus was just used. However, this results in a bunch of random, unidentifiable characters flashing on the screen. I tested to see if both seconds and minutes work separate, which they do, so I think it is in the syntax of lcd.print(). I was not able to find this addressed anywhere else. Help would be appreciated.

Code:

#include <LiquidCrystal.h>



LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int seconds;
int minutes;
int timedif;
int starttime = -1;

void setup()
{

    lcd.begin(16, 2); //Initialize the 16x2 LCD


    lcd.clear();    //Clear any old data displayed on the LCD
}

void loop()
{

  lcd.setCursor(0,0);
  lcd.print("Stopwatch");
  lcd.setCursor(0,1);
  if (starttime == -1) { //if running first time, time dif is initiated
    starttime = millis();
  }

  timedif = (millis() - starttime)/1000; //will get difference in terms of seconds

  minutes = floor(timedif/60); // divides by sixty, drops decimal
  seconds = timedif%60; //gets remainder of divided by 60
  lcd.print(minutes + ";" + seconds);

}
1

1 Answers

0
votes

What you are printing is a JAVA syntax , and Arduino is using C syntax. See this on how you need to use this API.

You need to build the string (for example as char array) and passed it to the print method