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
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);
}
}