// LCD1602 and Pi Pico!
#include <BitBang_LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2, 20, 21);
int yesButton = 16;
int noButton = 22;
int yesDefaultValue = HIGH; // Pin 16 defaults to HIGH
int noDefaultValue = HIGH; // Pin 22 defaults to HIGH
String intro = "Hi, user";
struct Question {
const char* question;
const char* answerYes;
const char* answerNo;
};
// Match totalQuestions to questions amount
int totalQuestions = 3;
// Questions need to fit in first row due to library not allowing new lines with "\n"
Question questions[] = {
{"You like cats?", "Me too!", "Oh...ew"},
{"Are you cool?", "Awesome!", "Oh, sorry :("},
{"Is this neat?", "Hell yeah!","Weird take..."}
};
// Init all bools to false to begin
bool introFinished = false;
bool questionDisplayed = false;
bool yesAnswerDisplayed = false;
bool noAnswerDisplayed = false;
bool questionsEnded = false;
int qIndex = 0;
void setup() {
boot_seq();
if (introFinished)
{
intro = "";
questionDisplayed = true;
yesAnswerDisplayed = false;
noAnswerDisplayed = false;
}
pinMode(yesButton, INPUT_PULLUP);
pinMode(noButton, INPUT_PULLUP);
}
void loop() {
int yesNewValue = digitalRead(yesButton);
int noNewValue = digitalRead(noButton);
if (questionDisplayed)
{
lcd.clear();
lcd.print(questions[qIndex].question);
questionDisplayed = false;
}
if (yesAnswerDisplayed)
{
lcd.clear();
delay(1250);
lcd.print(questions[qIndex].answerYes);
yesAnswerDisplayed = false;
delay(1500);
qIndex += 1;
lcd.clear();
lcd.print("Loading next\n");
lcd.setCursor(0, 1);
lcd.print("Question...");
Serial.println(qIndex);
delay(1500);
lcd.clear();
questionDisplayed = true;
return;
}
if (noAnswerDisplayed)
{
lcd.clear();
delay(1250);
lcd.print(questions[qIndex].answerNo);
noAnswerDisplayed = false;
delay(1500);
qIndex += 1;
lcd.clear();
lcd.print("Loading next\n");
lcd.setCursor(0, 1);
lcd.print("Question...");
Serial.println(qIndex);
delay(1500);
lcd.clear();
questionDisplayed = true;
return;
}
if (qIndex >= 3 && !questionsEnded)
{
lcd.clear();
lcd.print("No questions");
lcd.setCursor(0,1);
lcd.print("left");
questionsEnded = true;
delay(2000);
lcd.clear();
end_seq();
return;
}
// Yes Button
if (yesNewValue == LOW) yesAnswerDisplayed = true;
// No Button
if (noNewValue == LOW) noAnswerDisplayed = true;
}
void boot_seq()
{
turn_on();
lcd.print("LOADING");
delay(1000);
lcd.print(".");
delay(1000);
lcd.print(".");
delay(1000);
lcd.print(".");
delay(2500);
lcd.clear();
lcd.print(intro);
delay(2500);
lcd.setCursor(0, 1);
lcd.print("Let's start...");
delay(1250);
lcd.clear();
introFinished = true;
}
void end_seq()
{
lcd.print("THANK YOU 4");
lcd.setCursor(0,1);
lcd.print("PLAYING!");
delay(1500);
lcd.clear();
lcd.print(".");
delay(1000);
lcd.print(".");
delay(1000);
lcd.print(".");
delay(1000);
lcd.clear();
lcd.print("SHUTTING");
lcd.setCursor(0,1);
lcd.print("DOWN!");
delay(5000);
lcd.clear();
shut_off();
}
void turn_on()
{
lcd.init();
lcd.backlight();
}
void shut_off()
{
lcd.noDisplay();
lcd.noBacklight();
}