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: Event Navigator
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-09-09 13:52:51
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* code a view Event page where at a click of more */
- /* details shows a detailed decription of on single */
- /* item and not the details of all the items in the */
- /* view-event page */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- // Event viewer UI on Arduino Uno using Serial Monitor
- // Provides a "View Event" page style: iterate through events with NEXT button
- // and view details of a single item with MORE button. BACK returns to list view.
- // Global constants and state for the simple event viewer
- const int NUM_EVENTS = 3; // Number of events in the list
- const int NEXT_BTN_PIN = 2; // Button to go to next item
- const int MORE_BTN_PIN = 3; // Button to view details of current item
- const int BACK_BTN_PIN = 4; // Button to go back to list from details
- enum ViewMode { LIST_VIEW, DETAIL_VIEW };
- ViewMode mode = LIST_VIEW;
- int currentIndex = 0; // Index of the currently selected event
- // Event data: titles and descriptions. Stored as string literals to keep RAM usage low.
- const char* event_titles[NUM_EVENTS] = {
- "Event Alpha",
- "Event Beta",
- "Event Gamma"
- };
- const char* event_descs[NUM_EVENTS] = {
- "Details: Event Alpha is about system requirements, event planning and scheduling. This is a detailed description for Alpha.",
- "Details: Event Beta covers user interaction, interfaces, and navigation. Detailed view for Beta.",
- "Details: Event Gamma focuses on hardware integration, serial I/O and debouncing. This is Gamma's detailed description."
- };
- // Debounce state for buttons
- bool lastNextState = false;
- bool lastMoreState = false;
- bool lastBackState = false;
- // Forward declarations of rendering and utility functions
- void renderListView();
- void renderDetailView();
- bool isPressed(int pin, bool &lastState);
- void setup(void)
- {
- // put your setup code here, to run once:
- Serial.begin(9600);
- // Initialize pushbutton pins with internal pull-up resistors
- pinMode(NEXT_BTN_PIN, INPUT_PULLUP);
- pinMode(MORE_BTN_PIN, INPUT_PULLUP);
- pinMode(BACK_BTN_PIN, INPUT_PULLUP);
- // Initial view
- mode = LIST_VIEW;
- currentIndex = 0;
- Serial.println("Event Viewer Initialized.");
- renderListView();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- switch (mode)
- {
- case LIST_VIEW:
- if (isPressed(NEXT_BTN_PIN, lastNextState))
- {
- currentIndex = (currentIndex + 1) % NUM_EVENTS;
- renderListView();
- }
- if (isPressed(MORE_BTN_PIN, lastMoreState))
- {
- mode = DETAIL_VIEW;
- renderDetailView();
- }
- break;
- case DETAIL_VIEW:
- if (isPressed(BACK_BTN_PIN, lastBackState))
- {
- mode = LIST_VIEW;
- renderListView();
- }
- break;
- }
- }
- void renderListView()
- {
- Serial.println("View Events - List");
- Serial.print("Event ");
- Serial.print(currentIndex + 1);
- Serial.print(": ");
- Serial.println(event_titles[currentIndex]);
- Serial.println("Press NEXT to cycle events, MORE for details.");
- }
- void renderDetailView()
- {
- Serial.println("Event Details");
- Serial.print("Title: ");
- Serial.println(event_titles[currentIndex]);
- Serial.print("Details: ");
- Serial.println(event_descs[currentIndex]);
- Serial.println("Press BACK to return to list.");
- }
- bool isPressed(int pin, bool &lastState)
- {
- bool current = digitalRead(pin) == LOW; // Active LOW
- if (current && !lastState)
- {
- lastState = true;
- delay(50); // debounce
- return true;
- }
- if (!current)
- lastState = false;
- return false;
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment