0

I am trying to make a timer that has a accuracy up to 1 tenth of a second. However when it is suppose to print "0", it will print an "A". For example, when printing "10", it will print "1A". This program only lasts up to seconds. Any suggestion is highly appreciated, thank you!

#include <Wire.h>  
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
unsigned long time2 = 0;
int x = 0;
int a = 0;
int b = 0;
void setup() {
  lcd.begin(16,2);
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("00:00:00:0      ");
  Serial.begin(9600);
}

void loop() {
  unsigned long time1;
  time1 = millis();
  if (time1 - time2 > 100){
    time2 = time1;
    lcd.setCursor (9,0);
    x=x+1;
    lcd.print(x," ");
  }
  if (x>=10){
    x=0;
    a=a+1;
    lcd.setCursor(7,0);
    lcd.print(a,":");
  }
  if (a>=10){
    a=0;
    b=b+1;
    lcd.setCursor(6,0);
    lcd.print(b+a);
  }
}
0

Here is my Suggestion: In cases a clear answer could not be seen, you have to remove any weaknesses step by step to further encircle the problem. Since there is now answer for more than a month, I assume this as an appropriate proceeding.

One weakness I see in your coding is, that you are counting your values x, a, b, up to ten and you are printing them bevor reseting them to Zero, so your are printing 'x' even if it is ten. If for any reason in the further handling your display shows HEX values, you will end up displaying an 'A'. Change your Code so that values > 9 are not printed out, than this weakness will be removed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.