#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define LED_DAY 2
#define LED_EVENING 3
#define LED_NIGHT 4
#define LIGHT_SENSOR_PIN A0
LiquidCrystal_I2C lcd(0x27, 16, 2); // Inicializo LCDi2c 0x27
void setup() {
pinMode(LED_DAY, OUTPUT);
pinMode(LED_EVENING, OUTPUT);
pinMode(LED_NIGHT, OUTPUT);
lcd.begin();
lcd.backlight();
}
void loop() {
int lightLevel = analogRead(LIGHT_SENSOR_PIN);
String timeOfDay;
if (lightLevel > 800) { // Daytime threshold
digitalWrite(LED_DAY, HIGH);
digitalWrite(LED_EVENING, LOW);
digitalWrite(LED_NIGHT, LOW);
timeOfDay = "MaƱana";
} else if (lightLevel > 400) { // Evening threshold
digitalWrite(LED_DAY, LOW);
digitalWrite(LED_EVENING, HIGH);
digitalWrite(LED_NIGHT, LOW);
timeOfDay = "Tarde";
} else { // Nighttime
digitalWrite(LED_DAY, LOW);
digitalWrite(LED_EVENING, LOW);
digitalWrite(LED_NIGHT, HIGH);
timeOfDay = "Noche";
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Tiempo del dia:");
lcd.setCursor(0, 1);
lcd.print(timeOfDay);
delay(1000); // Update every second
}
I'm sure you'll agree that sharing the complete error message, enclosed with the <CODE/>
tool as you've already done with your sketch, would go a long way towards enabling anyone to diagnose what your problem might be. I never paid attention in mind reading class as a child, and apparently neither did anyone else.
Please post the complete error message, using code tags.
We can't help if we don't see ALL the verbose verify output in code tags.
You must use
lcd.init();
instead
lcd.begin();