Advertisement
pleasedontcode

Button Display rev_01

Feb 19th, 2024
64
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: Button Display
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-02-19 09:23:15
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* This code will arduino uno to 1602 I2C LCD. show */
  21.     /* initial message "Welcome to PES" in 1st line. */
  22.     /* "Charging Station" in 2nd line. after 5 seconds */
  23.     /* delay, show message "Press Button to" in 1st line. */
  24.     /* "Start Charging" in 2nd line. when momentary */
  25.     /* contact but */
  26. /****** SYSTEM REQUIREMENT 2 *****/
  27.     /* This code will arduino uno to 1602 I2C LCD. show */
  28.     /* initial message "Welcome to PES" in 1st line. */
  29.     /* "Charging Station" in 2nd line. after 5 seconds */
  30.     /* delay, show message "Press Button to" in 1st line. */
  31.     /* "Start Charging" in 2nd line. when momentary */
  32.     /* contact but */
  33. /****** END SYSTEM REQUIREMENTS *****/
  34.  
  35. /****** DEFINITION OF LIBRARIES *****/
  36. #include <EasyButton.h>    //https://github.com/evert-arias/EasyButton
  37. #include <Wire.h>          // I2C communication library
  38. #include <LiquidCrystal_I2C.h>   // LCD library
  39.  
  40. /****** FUNCTION PROTOTYPES *****/
  41. void setup(void);
  42. void loop(void);
  43.  
  44. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  45. const uint8_t Button_PushButton_PIN_D2    = 2;
  46. const uint8_t Button_PushButton_PIN_D3    = 3;
  47.  
  48. /****** DEFINITION OF LCD PARAMETERS *****/
  49. const int LCD_ADDRESS = 0x27; // I2C address of the LCD module
  50. const int LCD_COLUMNS = 16;   // Number of columns in the LCD module
  51. const int LCD_ROWS = 2;       // Number of rows in the LCD module
  52.  
  53. /****** DEFINITION OF LIBRARIES CLASS INSTANCES *****/
  54. EasyButton button1(Button_PushButton_PIN_D2);
  55. EasyButton button2(Button_PushButton_PIN_D3);
  56. LiquidCrystal_I2C lcd(LCD_ADDRESS, LCD_COLUMNS, LCD_ROWS); // Create an object for the LCD module
  57.  
  58. void setup(void)
  59. {
  60.   // put your setup code here, to run once:
  61.   lcd.begin(LCD_COLUMNS, LCD_ROWS); // Initialize the LCD module
  62.   lcd.print("Welcome to PES"); // Print the welcome message on the first line
  63.   lcd.setCursor(0, 1); // Move the cursor to the second line
  64.   lcd.print("Charging Station"); // Print the charging station message on the second line
  65.   delay(5000); // Delay for 5 seconds
  66.  
  67.   lcd.clear(); // Clear the LCD screen
  68.   lcd.print("Press Button to"); // Print the "Press Button to" message on the first line
  69.   lcd.setCursor(0, 1); // Move the cursor to the second line
  70.   lcd.print("Start Charging"); // Print the "Start Charging" message on the second line
  71.  
  72.   pinMode(Button_PushButton_PIN_D2, INPUT_PULLUP);
  73.   pinMode(Button_PushButton_PIN_D3, INPUT_PULLUP);
  74. }
  75.  
  76. void loop(void)
  77. {
  78.   // put your main code here, to run repeatedly:
  79.   button1.read(); // Read the state of button1
  80.   button2.read(); // Read the state of button2
  81.  
  82.   // Check if button1 is pressed
  83.   if (button1.isPressed())
  84.   {
  85.     lcd.clear(); // Clear the LCD screen
  86.     lcd.print("Button 1 Pressed"); // Print the button1 pressed message on the first line
  87.     lcd.setCursor(0, 1); // Move the cursor to the second line
  88.     lcd.print("Start Charging"); // Print the "Start Charging" message on the second line
  89.   }
  90.  
  91.   // Check if button2 is pressed
  92.   if (button2.isPressed())
  93.   {
  94.     lcd.clear(); // Clear the LCD screen
  95.     lcd.print("Button 2 Pressed"); // Print the button2 pressed message on the first line
  96.     lcd.setCursor(0, 1); // Move the cursor to the second line
  97.     lcd.print("Start Charging"); // Print the "Start Charging" message on the second line
  98.   }
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement