Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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: **Menu Display**
- - Source Code NOT compiled for: ESP32 DevKit V1
- - Source Code created on: 2024-12-29 16:34:32
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* 1 have 2 buttons 1 ssd1306 display i want an */
- /* intervace to choose from 4 options */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <SSD1306.h>
- #include <EasyButton.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void displayOptions(int selectedOption);
- void handleButtonPress(void);
- /****** GLOBAL VARIABLES *****/
- SSD1306 display(0x3C, 4, 5); // I2C address, SDA, SCL pins
- EasyButton button1(2); // Button 1 on pin 2
- EasyButton button2(3); // Button 2 on pin 3
- int selectedOption = 0; // Variable to track the selected option
- void setup(void)
- {
- // Initialize the display
- display.init();
- display.clear();
- display.display();
- // Initialize buttons
- button1.begin();
- button2.begin();
- // Set button press handlers
- button1.onPressed([]() {
- selectedOption = (selectedOption + 1) % 4; // Cycle through options
- displayOptions(selectedOption);
- });
- button2.onPressed([]() {
- selectedOption = (selectedOption - 1 + 4) % 4; // Cycle backwards through options
- displayOptions(selectedOption);
- });
- // Display the initial options
- displayOptions(selectedOption);
- }
- void loop(void)
- {
- // Update button states
- button1.update();
- button2.update();
- }
- void displayOptions(int selectedOption)
- {
- display.clear();
- display.setTextSize(1);
- display.setTextColor(WHITE);
- display.setCursor(0, 0);
- display.print("Select an option:");
- // Display options
- for (int i = 0; i < 4; i++) {
- if (i == selectedOption) {
- display.setTextColor(BLACK, WHITE); // Highlight selected option
- } else {
- display.setTextColor(WHITE);
- }
- display.setCursor(0, 10 + i * 10);
- display.print("Option ");
- display.print(i + 1);
- }
- display.display();
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement