/********* Pleasedontcode.com **********
Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- Terms and Conditions:
You have a non-exclusive, revocable, worldwide, royalty-free license
for personal and commercial use. Attribution is optional; modifications
are allowed, but you're responsible for code maintenance. We're not
liable for any loss or damage. For full terms,
please visit pleasedontcode.com/termsandconditions.
- Project: **Quiz Display**
- Source Code NOT compiled for: Arduino Uno
- Source Code created on: 2024-11-14 15:06:13
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* A quiz game, where it will use tts voice with the */
/* speaker, and it will ask questions with 2 choices, */
/* and there is red button (left) and yellow button */
/* (right) It will display the choices on the OLED */
/* Display. */
/****** END SYSTEM REQUIREMENTS *****/
/* START CODE */
/****** DEFINITION OF LIBRARIES *****/
#include
#include //https://github.com/evert-arias/EasyButton
#include //https://github.com/stblassitude/Adafruit_SSD1306_Wemos_OLED.git
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void displayQuestion(const char* question, const char* option1, const char* option2);
void checkAnswer(bool answer);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t RedButton_PushButton_PIN_D2 = 2;
const uint8_t YellowButton_PushButton_PIN_D3 = 3;
/***** DEFINITION OF I2C PINS *****/
const uint8_t OLED_SSD1306OledDisplay_I2C_PIN_SDA_A4 = A4;
const uint8_t OLED_SSD1306OledDisplay_I2C_PIN_SCL_A5 = A5;
const uint8_t OLED_SSD1306OledDisplay_I2C_SLAVE_ADDRESS = 60;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
// Create instances for the buttons
EasyButton redButton(RedButton_PushButton_PIN_D2);
EasyButton yellowButton(YellowButton_PushButton_PIN_D3);
// Create instance for the OLED display
Adafruit_SSD1306 display(128, 32); // Initialize with width and height
void setup(void)
{
// put your setup code here, to run once:
pinMode(RedButton_PushButton_PIN_D2, INPUT_PULLUP);
pinMode(YellowButton_PushButton_PIN_D3, INPUT_PULLUP);
// Initialize the display
display.begin(SSD1306_SWITCHCAPVCC, OLED_SSD1306OledDisplay_I2C_SLAVE_ADDRESS);
display.clearDisplay();
display.display();
// Initialize buttons
redButton.begin();
yellowButton.begin();
}
void loop(void)
{
// Update button states
redButton.read();
yellowButton.read();
// Display a question
displayQuestion("Is the sky blue?", "Red: No", "Yellow: Yes");
// Check for button presses
if (redButton.pressed()) {
checkAnswer(false); // Red button pressed
}
if (yellowButton.pressed()) {
checkAnswer(true); // Yellow button pressed
}
// Add a small delay to avoid bouncing
delay(100);
}
void displayQuestion(const char* question, const char* option1, const char* option2) {
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0);
display.println(question);
display.setCursor(0, 16);
display.println(option1);
display.setCursor(0, 24);
display.println(option2);
display.display();
}
void checkAnswer(bool answer) {
if (answer) {
// Correct answer logic
display.clearDisplay();
display.setCursor(0, 0);
display.println("Correct!");
} else {
// Incorrect answer logic
display.clearDisplay();
display.setCursor(0, 0);
display.println("Incorrect!");
}
display.display();
delay(2000); // Show result for 2 seconds
}
/* END CODE */