Advertisement
pleasedontcode

Menu_Selection rev_02

Nov 21st, 2023
86
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: Menu_Selection
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-11-22 05:54:12
  15.     - Source Code generated by: Gavin
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20.  
  21. /****** SYSTEM REQUIREMENT 1 *****/
  22. /* when start is pushed it needs to bring up a menu */
  23. /* with 3 selections. 1.date and Time setting, 2. */
  24. /* Customer name and 3. Label Format. 0 . Back to */
  25. /* main menu , 99 Exit */
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void showMenu(void);
  31. void processSelection(int selection);
  32.  
  33. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  34. const uint8_t Start_PIN_D2 = 2;
  35.  
  36. void setup(void)
  37. {
  38.   // Initialize serial communication
  39.   Serial.begin(9600);
  40.  
  41.   // Set the pin mode for start button
  42.   pinMode(Start_PIN_D2, INPUT);
  43. }
  44.  
  45. void loop(void)
  46. {
  47.   // Read the start button state
  48.   int startButtonState = digitalRead(Start_PIN_D2);
  49.  
  50.   if (startButtonState == HIGH)
  51.   {
  52.     showMenu(); // Display the menu when the start button is pressed
  53.  
  54.     while (startButtonState == HIGH)
  55.     {
  56.       startButtonState = digitalRead(Start_PIN_D2); // Continue reading the start button state to see if it's still pressed
  57.       delay(100);
  58.     }
  59.   }
  60. }
  61.  
  62. void showMenu()
  63. {
  64.   // Display the menu options
  65.   Serial.println("Menu Options:");
  66.   Serial.println("1. Date and Time Setting");
  67.   Serial.println("2. Customer Name");
  68.   Serial.println("3. Label Format");
  69.   Serial.println("0. Back to Main Menu");
  70.   Serial.println("99. Exit");
  71.  
  72.   // Wait for user input
  73.   while (Serial.available() == 0)
  74.   {
  75.     delay(100);
  76.   }
  77.  
  78.   // Process the user selection
  79.   int selection = Serial.parseInt();
  80.   processSelection(selection);
  81. }
  82.  
  83. void processSelection(int selection)
  84. {
  85.   switch (selection)
  86.   {
  87.     case 1:
  88.       // Date and Time Setting functionality
  89.       Serial.println("Setting Date and Time...");
  90.       // Add your code here to set date and time
  91.       break;
  92.     case 2:
  93.       // Customer Name functionality
  94.       Serial.println("Editing Customer Name...");
  95.       // Add your code here to edit customer name
  96.       break;
  97.     case 3:
  98.       // Label Format functionality
  99.       Serial.println("Selecting Label Format...");
  100.       // Add your code here to select label format
  101.       break;
  102.     case 0:
  103.       // Back to Main Menu functionality
  104.       Serial.println("Going back to Main Menu...");
  105.       // Add your code here to go back to main menu
  106.       break;
  107.     case 99:
  108.       // Exit functionality
  109.       Serial.println("Exiting...");
  110.       // Add your code here to exit the program
  111.       break;
  112.     default:
  113.       // Invalid selection
  114.       Serial.println("Invalid selection!");
  115.       break;
  116.   }
  117. }
  118.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement