I would like to know what I am missing in the code, when it prints out on the LCD display, it is only printing out one digits. (“0:0:0:0:0”).
I like to know how to make a print out and run the numbers like this.
("00:00:00:00")
Has something to do with this line.
h=0;
lcd.print(h);
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
int h,m,s,ms;
LiquidCrystal_I2C lcd(0x27, 16, 2);
int start = 8; // the number of the pushbutton pin
int Stop = 9; // the number of the LED pin
int buttonState1; // variable for reading the pushbutton status
int buttonState2; // variable for reading the pushbutton status
void setup() {
Serial.begin(9600);
pinMode(start, INPUT);
pinMode(Stop, INPUT);
lcd.begin();
lcd.clear();
lcd.print("Time Stop");
lcd.setCursor(0,1);
lcd.print("00:00:00:00");
}
void loop()
{
buttonState1 = digitalRead(start);
buttonState2 = digitalRead(Stop);
Serial.println(buttonState1);
Serial.println(buttonState2);
if(buttonState1 == HIGH)
{
ms=0;
s=0;
m=0;
h=0;
lcd.setCursor(0,1);
lcd.print(h);
lcd.print(':');
lcd.print(m);
lcd.print(':');
lcd.print(s);
lcd.print(':');
lcd.print(ms);
lcd.print(" ");
delay(250);
}
if(buttonState2 == HIGH)
{
ms++;
delay(100);
if(ms==10){
ms=0;
s++;
delay(100);
if(s==60){
s=0;
m++;
delay(100);
}
if(m==60){
m=0;
h++;
delay(100);
}
if(h==1){
h=0;
m=0;
s=0;
ms=0;
ms++;
}
}
Serial.println();
lcd.setCursor(0,1);
lcd.print(h);
lcd.print(':');
lcd.print(m);
lcd.print(':');
lcd.print(s);
lcd.print(':');
lcd.print(ms);
lcd.print(" ");
}
}
[\code]