In project 11 - The Crystall Ball, I'm trying to use a photoresistor instead of the tilt sensor.
So, every time I put my hand over the photoresistor (given a constant light source in the room) and cast a shadow over it,
the new current value (different from initial value) would trigger the random answers.
But no characters show up on the LCD. It only lightens up.
What am I doing wrong?
Here's the code:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int sensorPin = A0;
int sensorValue;
int sensorTop = 1023;
int initialSensorValue;
int reply;
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
pinMode(sensorPin, INPUT);
lcd.print("Ask");
lcd.setCursor(0, 1);
lcd.print("Mighty Mithras");
sensorValue = analogRead(sensorPin);
if (sensorValue < sensorTop) {
sensorTop = initialSensorValue;
}
}
void loop() {
sensorValue = analogRead(sensorPin);
Serial.print(sensorValue);
if (sensorValue < initialSensorValue) {
reply = random(8);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("The Ball says:");
lcd.setCursor(0, 1);
switch (reply) {
case 0:
lcd.print("Yes");
break;
case 1:
lcd.print("Most likely");
break;
case 2:
lcd.print("Certainly");
break;
case 3:
lcd.print("Outlook Good");
break;
case 4:
lcd.print("Unsure");
break;
case 5:
lcd.print("Ask Again");
break;
case 6:
lcd.print("Doubtful");
break;
case 7:
lcd.print("No");
break;
}
}
}