#include <LiquidCrystal.h>
const float GAMMA = 1.2;
const float RL10 = 20.0;
int itera = 0;
byte light[8] = {
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111,
B11111
};
byte dark[8] = {
B11111,
B10001,
B10001,
B10001,
B10001,
B10001,
B10001,
B11111
};
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
lcd.begin(16, 2);
pinMode(2, INPUT);
lcd.createChar(1, light);
lcd.createChar(2, dark);
lcd.setCursor(0,0);
lcd.noAutoscroll();
}
void loop()
{
// Convert the analog value into lux value:
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));
if(lux >= 1)
{
lcd.setCursor(itera,0);
if(lux >= 20.00)
{
lcd.setCursor(itera,0);
lcd.write(byte(1));
lcd.setCursor(0,1);
lcd.print("Light");
}
else
{
lcd.setCursor(itera,0);
lcd.write(byte(2));
lcd.setCursor(0,1);
lcd.print("Dark!");
}
}
else
{
lcd.clear();
lcd.setCursor(0,1);
lcd.print("Sensor Off.");
lcd.print(itera);
delay(500);
}
delay(1000);
itera = itera + 1;
int digVal = digitalRead(2);
if (digVal == 1)
{
itera = 0;
lcd.setCursor(0,1);
lcd.print("New Letter!");
lcd.print(digVal);
delay(3000);
lcd.clear();
}
else
{
delay(100);
}
}