to start want to say I am new to the forums and arduino I have been trying to figure out how to use a LDR to control the backlight of my LCD but when i thought i had it i get nothing can someone look at this code and tell me what i am messing up please ?
// include the library code:
#include <LiquidCrystal.h>
#include <Wire.h>
#include <RTClib.h>
// #define LDR A1
RTC_DS1307 rtc;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int LDR_pin = A1;
int back_lighth = A2;
int back_lightl = A0;
int LDR_out;
int pwm_back_light;
void setup() {
lcd.begin(16, 2);
if (!rtc.begin()) {
lcd.begin(16, 2);
lcd.print("Couldn't find RTC");
delay(1000);
while (true);
}
rtc.adjust(DateTime(F(DATE), F(TIME)));
}
void loop() {
int LDR_ou = analogRead(LDR_pin);
if (LDR_ou <= 800) {
Serial.print(" hi ");
analogWrite(back_lightl, HIGH);
analogWrite(back_lighth, LOW);
}
else {
Serial.print(" bye" );
analogWrite(back_lightl, LOW);
analogWrite(back_lighth, HIGH);
}
DateTime now = rtc.now();
lcd.setCursor(0, 0);
lcd.print(now.hour(), DEC);
lcd.print(":");
lcd.print(now.minute(), DEC);
lcd.print(":");
lcd.print(now.second(), DEC);
lcd.setCursor(0, 1);
lcd.print(now.day(), DEC);
lcd.print(":");
lcd.print(now.month(), DEC);
lcd.print(":");
lcd.print(now.year(), DEC);
lcd.print("");
delay(1000);
}