#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
const int redd = A3;
const int greenn = A2;
const int bluee = A1;
const int trueB = 2;
const int falseB = 1;
const char* questions[] = {
"Pogi si butlig?",
"is 1 + 1 = 3?",
"Is 2 + 2 = 4?"
};
bool answers[] = {true, false, true};
int currentQuestionIndex = 0;
void setup() {
lcd.begin(16, 2);
lcd.backlight();
pinMode(redd, OUTPUT);
pinMode(greenn, OUTPUT);
pinMode(bluee, OUTPUT);
pinMode(trueB, INPUT_PULLUP);
pinMode(falseB, INPUT_PULLUP);
displayQuestion();
}
void loop() {
if (digitalRead(trueB) == LOW) {
if (answers[currentQuestionIndex]) {
setRGB(0, 255, 0);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("True!");
} else {
setRGB(255, 0, 0);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("False!");
}
delay(2000);
resetState();
}
if (digitalRead(falseB) == LOW) {
if (!answers[currentQuestionIndex]) {
setRGB(0, 255, 0);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Correct!");
} else {
setRGB(255, 0, 0);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Wrong!");
}
delay(2000);
resetState();
}
}
void resetState() {
currentQuestionIndex++;
if (currentQuestionIndex >= sizeof(questions) / sizeof(questions[0])) {
currentQuestionIndex = 0;
}
displayQuestion();
}
void displayQuestion() {
lcd.clear();
const char* question = questions[currentQuestionIndex];
lcd.setCursor(0, 0);
lcd.print(question);
setRGB(0, 0, 255);
}
void setRGB(int red, int green, int blue) {
analogWrite(redd, red);
analogWrite(greenn, green);
analogWrite(bluee, blue);
}