Advertisement
pleasedontcode

**Button Status** rev_01

Nov 24th, 2024
83
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 Status**
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2024-11-24 21:10:56
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* this    part,   your    Arduino board’s LCD */
  21.     /* display will    appear  have    the */
  22.     /* following       display when    no      button  is */
  23.     /* being   pressed:  and     the     following */
  24.     /* display when    any     button  is      being */
  25.     /* pressed:  and     this    behavior */
  26.     /* continues as    long    as      the     Arduino */
  27.     /* runs */
  28. /****** END SYSTEM REQUIREMENTS *****/
  29.  
  30. /* START CODE */
  31.  
  32. /****** DEFINITION OF LIBRARIES *****/
  33. #include <Wire.h>
  34. #include <LiquidCrystal_I2C.h>  //https://github.com/marcoschwartz/LiquidCrystal_I2C
  35.  
  36. /****** FUNCTION PROTOTYPES *****/
  37. void setup(void);
  38. void loop(void);
  39.  
  40. /***** DEFINITION OF I2C PINS *****/
  41. const uint8_t LCD_LCD1602I2C_I2C_PIN_SDA_D20        = 20;
  42. const uint8_t LCD_LCD1602I2C_I2C_PIN_SCL_D21        = 21;
  43. const uint8_t LCD_LCD1602I2C_I2C_SLAVE_ADDRESS      = 39;
  44.  
  45. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  46. // Create an instance of the LiquidCrystal_I2C class
  47. LiquidCrystal_I2C lcd(LCD_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // 16 columns and 2 rows
  48.  
  49. /****** BUTTON PINS *****/
  50. const int buttonPin = 2; // Pin where the button is connected
  51.  
  52. void setup(void)
  53. {
  54.     // Initialize the LCD
  55.     lcd.begin(16, 2); // Initialize the LCD with the number of columns and rows
  56.     lcd.backlight(); // Turn on the backlight
  57.  
  58.     // Set the button pin as input
  59.     pinMode(buttonPin, INPUT);
  60.    
  61.     // Display initial message
  62.     lcd.print("No Button Pressed");
  63. }
  64.  
  65. void loop(void)
  66. {
  67.     // Check if the button is pressed
  68.     if (digitalRead(buttonPin) == HIGH) {
  69.         lcd.clear(); // Clear the display
  70.         lcd.print("Button Pressed"); // Display message when button is pressed
  71.     } else {
  72.         lcd.clear(); // Clear the display
  73.         lcd.print("No Button Pressed"); // Display message when no button is pressed
  74.     }
  75.  
  76.     delay(100); // Small delay to avoid flickering
  77. }
  78.  
  79. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement