/*
Photoresistor (LDR) Analog Demo
Copyright (C) 2021 Uri Shaked.
https://wokwi.com/arduino/projects/305193627138654786
*/
#include <LiquidCrystal_I2C.h>
#define LDR_PIN 2
#define SERVO 9
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
pinMode(LDR_PIN, INPUT);
Serial.begin(9600);
}
bool keypress(int voltage)
{
float voltageLevel = 1.5;
if (voltage > static_cast<int>(voltageLevel) ) {
return true;
} else {
return false;
};
if(command == 1)
{
SERVO == HIGH;
}
}
void loop() {
int analogValue = analogRead(A0);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
Serial.print("Voltage: ");
Serial.println(voltage);
Serial.print("Resistance: ");
Serial.println(resistance);
Serial.print("Result: ");
bool status = keypress(voltage);
Serial.println(status);
lcd.setCursor(2, 0);
lcd.print(" ");
delay(500);
}