#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 20
#define LCD_LINES 4
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
#define LDR_PIN 2
const float GAMMA = 0.7;
const float RL10 = 50;
#include <Stepper.h>
const int stepsPerRevolution = 200;
const int targetPositionLight = 0; // Világos célpozíció (0 fok)
const int targetPositionDark = stepsPerRevolution; // Sötét célpozíció (180 fok)
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
lcd.init();
lcd.backlight();
pinMode(LDR_PIN, INPUT);
myStepper.setSpeed(60);
}
void loop() {
int analogValue = analogRead(A0);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
lcd.setCursor(0, 0);
lcd.print("Fenyero: ");
if (lux > 50) {
lcd.print("Vilagos");
myStepper.step(stepsPerRevolution);
} else {
lcd.print("Sotet ");
myStepper.step(-stepsPerRevolution);
}
lcd.setCursor(0, 1);
lcd.print("Lux: ");
lcd.print(lux);
lcd.print(" ");
delay(100);
}