// include the LCD display
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int switchPin = 6;
int switchState = 0;
int prevSwitchState = 0;
int reply;
// name the buttons and say what port they are connected to
int button1 = 13;
int button2 = 10;
int button3 = 8;
// say what the button state is when they aren't pressed at the beginning
int buttonState = 0;
void setup() {
// make all the buttons be inputs
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
// have the LCD write the beginning message
lcd.begin(16, 2);
pinMode(switchPin, INPUT);
lcd.print("This is a");
lcd.setCursor(0, 1);
lcd.print("Book Quiz!");
}
void loop() {
// clear the LCD display and set the cursor
lcd.clear();
// make the LCD ask the first question
switchState = digitalRead(buttonState);
lcd.print("Pick a summer vacation:");
lcd.setCursor(0, 1);
lcd.print("1. San Francisco");
lcd.setCursor(0, 2);
lcd.print("2. London");
lcd.setCursor(0, 3);
lcd.print("3. Alaska");
// if button 1 is pressed
if (button1 == HIGH) {
lcd.clear();
lcd.setCursor(0,1);
lcd.print("You Picked San Francisco");
}
// if button 2 is pressed
if (button2 == HIGH) {
lcd.clear();
lcd.setCursor(0,1);
lcd.print("You Picked London");
}
// if button 3 is pressed
if (button3 == HIGH) {
lcd.clear();
lcd.setCursor(0,1);
lcd.print("You Picked Alaska");
}
// clear the LCD display and set the cursor
lcd.clear();
// make the LCD ask the second question
switchState = digitalRead(buttonState);
lcd.print("Pick an ice cream flavor:");
lcd.setCursor(0, 1);
lcd.print("1. Chunky Monkey");
lcd.setCursor(0, 2);
lcd.print("2. Strawberry");
lcd.setCursor(0, 3);
lcd.print("3. Mint Chip");
// if button 1 is pressed
if (button1 == HIGH) {
lcd.clear();
lcd.setCursor(0,1);
lcd.print("You Picked Chunky Monkey");
}
// if button 2 is pressed
if (button2 == HIGH) {
lcd.clear();
lcd.setCursor(0,1);
lcd.print("You Picked Strawberry");
}
// if button 3 is pressed
if (button3 == HIGH) {
lcd.clear();
lcd.setCursor(0,1);
lcd.print("You Picked Mint Chip");
}
// clear the LCD display and set the cursor
lcd.clear();
// make the LCD ask the third question and say answer
switchState = digitalRead(buttonState);
lcd.print("Pick a year:");
lcd.setCursor(0, 1);
lcd.print("1. 2005");
lcd.setCursor(0, 2);
lcd.print("2. 1847");
lcd.setCursor(0, 3);
lcd.print("3. 1997");
// if button 1 is pressed
if (button1 == HIGH) {
lcd.clear();
lcd.setCursor(0,1);
lcd.print("You Picked 2005");
delay(50);
lcd.setCursor(0, 2);
lcd.print("You Should Read Looking For Alaska");
}
// if button 2 is pressed
if (button2 == HIGH) {
lcd.clear();
lcd.setCursor(0,1);
lcd.print("You Picked 1847");
delay(50);
lcd.setCursor(0, 2);
lcd.print("You Should Read Wuthering Heights");
}
// if button 3 is pressed
if (button3 == HIGH) {
lcd.clear();
lcd.setCursor(0,1);
lcd.print("You Picked 1997");
delay(50);
lcd.setCursor(0, 2);
lcd.print("You Should Read Harry Potter");
}
}
Comments