#include <LiquidCrystal.h>
LiquidCrystal lcd1(12, 11, 10, 9, 8, 7);
LiquidCrystal lcd2(5, 4, 3, 2, 24, 22);
int itera = 1;
int darkCount = 0;
const float GAMMA = 1.2;
const float RL10 = 20.0;
byte light[8] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
byte dark[8] = {
B11111,
B10001,
B10001,
B10001,
B10001,
B10001,
B10001,
B11111
};
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(53, INPUT);
pinMode(51, INPUT);
pinMode(23, INPUT);
pinMode(25, INPUT);
pinMode(49, OUTPUT);
lcd2.createChar(1, light);
lcd2.createChar(2, dark);
lcd1.createChar(1, light);
lcd1.createChar(2, dark);
}
void loop(){
int analogValue = analogRead(A0);
float voltage = float(analogValue) / 1024.0 * 5.0;
float resistance = 2000.0 * voltage / (1.0 - voltage / 5.0);
float lux = pow(RL10 * 1e3 * pow(10.0, GAMMA) / resistance, (1.0 / GAMMA));
// put your main code here, to run repeatedly:
lcd1.home();
lcd2.home();
if(digitalRead(53) == HIGH){
lcd2.clear();
if(lux >= 20.00)
{
lcd1.clear();
lcd1.setCursor(itera,0);
lcd1.write(byte(1));
//lcd1.setCursor(0, 2);
//lcd1.print("Light");
darkCount = 0;
}
else
{
lcd1.clear();
lcd1.setCursor(itera, 0);
lcd1.write(byte(2));
//lcd1.setCursor(0, 2);
//lcd1.print("Dark!");
if(lux <= 1){
delay(10);
}
else
{
darkCount = darkCount + 1;
}
}
if(lux <= 1)
{
lcd1.clear();
lcd1.setCursor(0,1);
lcd1.print("Sensor Off ");
lcd1.print(itera);
delay(500);
}
}
if(digitalRead(51) == HIGH){
lcd1.clear();
lcd2.clear();
if(digitalRead(25) == HIGH){
lcd1.print("Light.");
}
else
{
lcd1.print("Dark!");
}
}
if(digitalRead(53) == LOW && digitalRead(51) == LOW){
lcd1.clear();
lcd2.clear();
lcd1.home();
lcd2.home();
lcd1.noDisplay();
lcd2.noDisplay();
//lcd1.print("Translator Off");
//lcd2.print("Translator Off");
digitalWrite(49, LOW);
}
else
{
digitalWrite(49, HIGH);
lcd1.display();
lcd2.display();
}
if(darkCount == 5){
darkCount = 0;
lcd2.setCursor(0,1);
lcd2.print("New Word");
itera = 0;
delay(2000);
}
else
{
lcd2.print(darkCount);
}
delay(1000);
itera = itera + 1;
}