#include <LiquidCrystal.h>
LiquidCrystal lcd( 12, 11, 5, 4, 3, 2);
const int buttonPin = 8;
int lastButtonState;
#define NUM_ANSWERS 7
const char * answerTable[NUM_ANSWERS] =
{
"yes",
"no",
"maybe",
"why?",
"tomorrow",
"I don't know",
"ask new question",
};
void setup()
{
lcd.begin( 2, 16);
lcd.setCursor( 0, 0);
lcd.print( "Ask a question");
lcd.setCursor( 0, 1);
lcd.print( "and press button");
delay( 2000);
lcd.clear();
pinMode( buttonPin, INPUT_PULLUP);
// Try to get a random start by using the noise of the analog input(s)
long seed = 12345678L + analogRead(0) + analogRead(1) + analogRead(2);
randomSeed( seed);
lastButtonState = digitalRead( buttonPin);
}
void loop()
{
int read = digitalRead( buttonPin);
if( read != lastButtonState)
{
lastButtonState = read;
if( read == LOW) // low when button is pressed
{
lcd.setCursor( 0,0);
int randomIndex = random( 0, NUM_ANSWERS);
lcd.print( answerTable[randomIndex]);
delay( 4000);
lcd.clear();
}
}
}