pleasedontcode

Event Viewer rev_02

Sep 9th, 2025
318
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 Viewer
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-09-09 14:06:09
  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 using niceguy */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <LiquidCrystal.h>
  31. #include <string.h>
  32.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36.  
  37. /****** GLOBALS FOR UI *****/
  38. // LCD pins (adjust if wiring differs)
  39. const int LCD_RS = 12;
  40. const int LCD_EN = 11;
  41. const int LCD_D4 = 5;
  42. const int LCD_D5 = 4;
  43. const int LCD_D6 = 3;
  44. const int LCD_D7 = 2;
  45.  
  46. // Button pins
  47. const int NEXT_BTN_PIN = 7;     // More / Next
  48. const int DETAIL_BTN_PIN = 6;   // Details (More)
  49. const int BACK_BTN_PIN = 8;     // Back to list
  50.  
  51. // Event data (titles and descriptions)
  52. const int NUM_EVENTS = 3;
  53. const char* event_titles[NUM_EVENTS] = {
  54.   "Event 1",
  55.   "Event 2",
  56.   "Event 3"
  57. };
  58.  
  59. const char* event_desc[NUM_EVENTS] = {
  60.   "Description for Event 1: A detailed description goes here.",
  61.   "Description for Event 2: Another detailed description goes here.",
  62.   "Description for Event 3: Yet another detailed description goes here."
  63. };
  64.  
  65. // Screen state
  66. enum Screen { LIST, DETAIL };
  67. Screen currentScreen = LIST;
  68. int currentIndex = 0;
  69.  
  70. // Debounce state
  71. int lastNextState = HIGH;
  72. int lastDetailState = HIGH;
  73. int lastBackState = HIGH;
  74. unsigned long debounceNext = 0;
  75. unsigned long debounceDetail = 0;
  76. unsigned long debounceBack = 0;
  77. const unsigned long DEBOUNCE_DELAY = 50; // ms
  78.  
  79. // LCD instance
  80. LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
  81.  
  82. // Show the list of events (single visible item at a time as per 16x2 display)
  83. void showListPage() {
  84.   lcd.clear();
  85.   lcd.setCursor(0, 0);
  86.   lcd.print("Event: ");
  87.   lcd.print(event_titles[currentIndex]);
  88.   lcd.setCursor(0, 1);
  89.   lcd.print("Next  Details");
  90. }
  91.  
  92. // Show detail for a specific event (wrap text into two 16-char lines)
  93. void showDetailPage(int idx) {
  94.   lcd.clear();
  95.   const char* desc = event_desc[idx];
  96.   char line1[17];
  97.   char line2[17];
  98.   strncpy(line1, desc, 16);
  99.   line1[16] = '\0';
  100.   strncpy(line2, desc + 16, 16);
  101.   line2[16] = '\0';
  102.   lcd.setCursor(0, 0);
  103.   lcd.print(line1);
  104.   lcd.setCursor(0, 1);
  105.   lcd.print(line2);
  106. }
  107.  
  108. void setup(void) {
  109.   // Initialize LCD and buttons
  110.   lcd.begin(16, 2);
  111.   pinMode(NEXT_BTN_PIN, INPUT_PULLUP);
  112.   pinMode(DETAIL_BTN_PIN, INPUT_PULLUP);
  113.   pinMode(BACK_BTN_PIN, INPUT_PULLUP);
  114.  
  115.   // Initial screen
  116.   currentIndex = 0;
  117.   currentScreen = LIST;
  118.   showListPage();
  119. }
  120.  
  121. void loop(void) {
  122.   // Read Next button (cycle through items)
  123.   int nextState = digitalRead(NEXT_BTN_PIN);
  124.   if (nextState != lastNextState) {
  125.     debounceNext = millis();
  126.   }
  127.   if ((millis() - debounceNext) > DEBOUNCE_DELAY) {
  128.     if (nextState == LOW && lastNextState == HIGH) {
  129.       if (currentScreen == LIST) {
  130.         currentIndex = (currentIndex + 1) % NUM_EVENTS;
  131.         showListPage();
  132.       }
  133.     }
  134.   }
  135.   lastNextState = nextState;
  136.  
  137.   // Read Details button (show detailed view for selected item)
  138.   int detailState = digitalRead(DETAIL_BTN_PIN);
  139.   if (detailState != lastDetailState) {
  140.     debounceDetail = millis();
  141.   }
  142.   if ((millis() - debounceDetail) > DEBOUNCE_DELAY) {
  143.     if (detailState == LOW && lastDetailState == HIGH) {
  144.       if (currentScreen == LIST) {
  145.         currentScreen = DETAIL;
  146.         showDetailPage(currentIndex);
  147.       }
  148.     }
  149.   }
  150.   lastDetailState = detailState;
  151.  
  152.   // Read Back button (return to list view)
  153.   int backState = digitalRead(BACK_BTN_PIN);
  154.   if (backState != lastBackState) {
  155.     debounceBack = millis();
  156.   }
  157.   if ((millis() - debounceBack) > DEBOUNCE_DELAY) {
  158.     if (backState == LOW && lastBackState == HIGH) {
  159.       if (currentScreen == DETAIL) {
  160.         currentScreen = LIST;
  161.         showListPage();
  162.       }
  163.     }
  164.   }
  165.   lastBackState = backState;
  166.  
  167.   // Short delay to reduce CPU usage
  168.   // delay(10);
  169. }
  170.  
  171. /* END CODE */
  172.  
Advertisement
Add Comment
Please, Sign In to add comment