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 Viewer
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-09-09 14:06:09
- ********* 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 using niceguy */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <LiquidCrystal.h>
- #include <string.h>
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /****** GLOBALS FOR UI *****/
- // LCD pins (adjust if wiring differs)
- const int LCD_RS = 12;
- const int LCD_EN = 11;
- const int LCD_D4 = 5;
- const int LCD_D5 = 4;
- const int LCD_D6 = 3;
- const int LCD_D7 = 2;
- // Button pins
- const int NEXT_BTN_PIN = 7; // More / Next
- const int DETAIL_BTN_PIN = 6; // Details (More)
- const int BACK_BTN_PIN = 8; // Back to list
- // Event data (titles and descriptions)
- const int NUM_EVENTS = 3;
- const char* event_titles[NUM_EVENTS] = {
- "Event 1",
- "Event 2",
- "Event 3"
- };
- const char* event_desc[NUM_EVENTS] = {
- "Description for Event 1: A detailed description goes here.",
- "Description for Event 2: Another detailed description goes here.",
- "Description for Event 3: Yet another detailed description goes here."
- };
- // Screen state
- enum Screen { LIST, DETAIL };
- Screen currentScreen = LIST;
- int currentIndex = 0;
- // Debounce state
- int lastNextState = HIGH;
- int lastDetailState = HIGH;
- int lastBackState = HIGH;
- unsigned long debounceNext = 0;
- unsigned long debounceDetail = 0;
- unsigned long debounceBack = 0;
- const unsigned long DEBOUNCE_DELAY = 50; // ms
- // LCD instance
- LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
- // Show the list of events (single visible item at a time as per 16x2 display)
- void showListPage() {
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Event: ");
- lcd.print(event_titles[currentIndex]);
- lcd.setCursor(0, 1);
- lcd.print("Next Details");
- }
- // Show detail for a specific event (wrap text into two 16-char lines)
- void showDetailPage(int idx) {
- lcd.clear();
- const char* desc = event_desc[idx];
- char line1[17];
- char line2[17];
- strncpy(line1, desc, 16);
- line1[16] = '\0';
- strncpy(line2, desc + 16, 16);
- line2[16] = '\0';
- lcd.setCursor(0, 0);
- lcd.print(line1);
- lcd.setCursor(0, 1);
- lcd.print(line2);
- }
- void setup(void) {
- // Initialize LCD and buttons
- lcd.begin(16, 2);
- pinMode(NEXT_BTN_PIN, INPUT_PULLUP);
- pinMode(DETAIL_BTN_PIN, INPUT_PULLUP);
- pinMode(BACK_BTN_PIN, INPUT_PULLUP);
- // Initial screen
- currentIndex = 0;
- currentScreen = LIST;
- showListPage();
- }
- void loop(void) {
- // Read Next button (cycle through items)
- int nextState = digitalRead(NEXT_BTN_PIN);
- if (nextState != lastNextState) {
- debounceNext = millis();
- }
- if ((millis() - debounceNext) > DEBOUNCE_DELAY) {
- if (nextState == LOW && lastNextState == HIGH) {
- if (currentScreen == LIST) {
- currentIndex = (currentIndex + 1) % NUM_EVENTS;
- showListPage();
- }
- }
- }
- lastNextState = nextState;
- // Read Details button (show detailed view for selected item)
- int detailState = digitalRead(DETAIL_BTN_PIN);
- if (detailState != lastDetailState) {
- debounceDetail = millis();
- }
- if ((millis() - debounceDetail) > DEBOUNCE_DELAY) {
- if (detailState == LOW && lastDetailState == HIGH) {
- if (currentScreen == LIST) {
- currentScreen = DETAIL;
- showDetailPage(currentIndex);
- }
- }
- }
- lastDetailState = detailState;
- // Read Back button (return to list view)
- int backState = digitalRead(BACK_BTN_PIN);
- if (backState != lastBackState) {
- debounceBack = millis();
- }
- if ((millis() - debounceBack) > DEBOUNCE_DELAY) {
- if (backState == LOW && lastBackState == HIGH) {
- if (currentScreen == DETAIL) {
- currentScreen = LIST;
- showListPage();
- }
- }
- }
- lastBackState = backState;
- // Short delay to reduce CPU usage
- // delay(10);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment