pleasedontcode

Event Navigator rev_01

Sep 9th, 2025
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: Event Navigator
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-09-09 13:52:51
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* code a view Event page where at a click of more */
  21.     /* details shows a detailed decription of on single */
  22.     /* item and not the details of all the items in the */
  23.     /* view-event page */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. // Event viewer UI on Arduino Uno using Serial Monitor
  36. // Provides a "View Event" page style: iterate through events with NEXT button
  37. // and view details of a single item with MORE button. BACK returns to list view.
  38.  
  39. // Global constants and state for the simple event viewer
  40. const int NUM_EVENTS = 3;            // Number of events in the list
  41. const int NEXT_BTN_PIN = 2;            // Button to go to next item
  42. const int MORE_BTN_PIN = 3;            // Button to view details of current item
  43. const int BACK_BTN_PIN = 4;            // Button to go back to list from details
  44.  
  45. enum ViewMode { LIST_VIEW, DETAIL_VIEW };
  46. ViewMode mode = LIST_VIEW;
  47.  
  48. int currentIndex = 0;                   // Index of the currently selected event
  49.  
  50. // Event data: titles and descriptions. Stored as string literals to keep RAM usage low.
  51. const char* event_titles[NUM_EVENTS] = {
  52.     "Event Alpha",
  53.     "Event Beta",
  54.     "Event Gamma"
  55. };
  56. const char* event_descs[NUM_EVENTS] = {
  57.     "Details: Event Alpha is about system requirements, event planning and scheduling. This is a detailed description for Alpha.",
  58.     "Details: Event Beta covers user interaction, interfaces, and navigation. Detailed view for Beta.",
  59.     "Details: Event Gamma focuses on hardware integration, serial I/O and debouncing. This is Gamma's detailed description."
  60. };
  61.  
  62. // Debounce state for buttons
  63. bool lastNextState = false;
  64. bool lastMoreState = false;
  65. bool lastBackState = false;
  66.  
  67. // Forward declarations of rendering and utility functions
  68. void renderListView();
  69. void renderDetailView();
  70. bool isPressed(int pin, bool &lastState);
  71.  
  72. void setup(void)
  73. {
  74.     // put your setup code here, to run once:
  75.     Serial.begin(9600);
  76.  
  77.     // Initialize pushbutton pins with internal pull-up resistors
  78.     pinMode(NEXT_BTN_PIN, INPUT_PULLUP);
  79.     pinMode(MORE_BTN_PIN, INPUT_PULLUP);
  80.     pinMode(BACK_BTN_PIN, INPUT_PULLUP);
  81.  
  82.     // Initial view
  83.     mode = LIST_VIEW;
  84.     currentIndex = 0;
  85.     Serial.println("Event Viewer Initialized.");
  86.     renderListView();
  87. }
  88.  
  89.  
  90. void loop(void)
  91. {
  92.     // put your main code here, to run repeatedly:
  93.     switch (mode)
  94.     {
  95.         case LIST_VIEW:
  96.             if (isPressed(NEXT_BTN_PIN, lastNextState))
  97.             {
  98.                 currentIndex = (currentIndex + 1) % NUM_EVENTS;
  99.                 renderListView();
  100.             }
  101.             if (isPressed(MORE_BTN_PIN, lastMoreState))
  102.             {
  103.                 mode = DETAIL_VIEW;
  104.                 renderDetailView();
  105.             }
  106.             break;
  107.         case DETAIL_VIEW:
  108.             if (isPressed(BACK_BTN_PIN, lastBackState))
  109.             {
  110.                 mode = LIST_VIEW;
  111.                 renderListView();
  112.             }
  113.             break;
  114.     }
  115. }
  116.  
  117. void renderListView()
  118. {
  119.     Serial.println("View Events - List");
  120.     Serial.print("Event ");
  121.     Serial.print(currentIndex + 1);
  122.     Serial.print(": ");
  123.     Serial.println(event_titles[currentIndex]);
  124.     Serial.println("Press NEXT to cycle events, MORE for details.");
  125. }
  126.  
  127. void renderDetailView()
  128. {
  129.     Serial.println("Event Details");
  130.     Serial.print("Title: ");
  131.     Serial.println(event_titles[currentIndex]);
  132.     Serial.print("Details: ");
  133.     Serial.println(event_descs[currentIndex]);
  134.     Serial.println("Press BACK to return to list.");
  135. }
  136.  
  137. bool isPressed(int pin, bool &lastState)
  138. {
  139.     bool current = digitalRead(pin) == LOW; // Active LOW
  140.     if (current && !lastState)
  141.     {
  142.         lastState = true;
  143.         delay(50); // debounce
  144.         return true;
  145.     }
  146.     if (!current)
  147.         lastState = false;
  148.     return false;
  149. }
  150.  
  151. /* END CODE */
  152.  
Advertisement
Add Comment
Please, Sign In to add comment