Error in arduino code for lcd display timer

So basically, this is a project where, when pressing a push-button, it turns on a light for ten seconds and switches it off until the button is pressed again. The countdown of ten seconds is visible in the serial monitor but I'm not able to display this same countdown on LCD display(I2c). Please help me edit my code. Thank you :slight_smile:

Moderator edit : Auto formatted the code in the IDE and posted back here in code tags to make it easier to copy

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
int x;
int y;
int c = 10;
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);
void setup()
{
  // Initiate the LCD:
  lcd.init();
  lcd.backlight();
  pinMode(8, INPUT);
  pinMode(9, OUTPUT);
  Serial.begin(9600);
}
void loop()
{
  y = digitalRead(8);
  if (y == HIGH)
  {
    digitalWrite(9, HIGH);
    lcd.setCursor(0, 0);
    lcd.print("light timer");
    for (x = c : x > 0; x -- )
    {
      Serial.println(x);
      lcd.setCursor(0, 1);
      lcd.print(x);
      delay(1000);
    }
    digitalWrite(9, LOW);
  }
}

for (x = c; x > 0; x–)
not sure if this is a display problem or logic but in the above line, i believe you intended "x--" not "x-"

note to moderator: the copied text include UTF characters for quotes, that need to be replaced with asciii characters.

Thanks for the report
Please try it now

looks good, not UTF chars
thanks

I am glad it is fixed

One day this forum software will behave the way we want rather than deciding what we meant

Hi;

 for (x = c : x > 0; x - )

Should be;

 for (x = c : x > 0; x -- )

Tom... :grinning: :+1: :coffee: :australia:

oh thank you so much
:slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.