Advertisement
pleasedontcode

**Button Status** rev_02

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:12:21
  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.  
  31. /********* User code review feedback **********
  32. #### Feedback 1 ####
  33. - not what i asked for
  34. ********* User code review feedback **********/
  35.  
  36. /* START CODE */
  37.  
  38. /****** DEFINITION OF LIBRARIES *****/
  39. #include <Wire.h>
  40. #include <LiquidCrystal_I2C.h>  //https://github.com/marcoschwartz/LiquidCrystal_I2C
  41.  
  42. /****** FUNCTION PROTOTYPES *****/
  43. void setup(void);
  44. void loop(void);
  45.  
  46. /***** DEFINITION OF I2C PINS *****/
  47. const uint8_t LCD_LCD1602I2C_I2C_PIN_SDA_D20        = 20;
  48. const uint8_t LCD_LCD1602I2C_I2C_PIN_SCL_D21        = 21;
  49. const uint8_t LCD_LCD1602I2C_I2C_SLAVE_ADDRESS      = 39;
  50.  
  51. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  52. // Create an instance of the LiquidCrystal_I2C class
  53. LiquidCrystal_I2C lcd(LCD_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // 16 columns and 2 rows
  54.  
  55. /****** BUTTON PINS *****/
  56. const int buttonPin = 2; // Pin where the button is connected
  57.  
  58. void setup(void)
  59. {
  60.     // Initialize the LCD
  61.     lcd.begin(16, 2); // Initialize the LCD with the number of columns and rows
  62.     lcd.backlight(); // Turn on the backlight
  63.  
  64.     // Set the button pin as input
  65.     pinMode(buttonPin, INPUT);
  66.    
  67.     // Display initial message
  68.     lcd.print("No Button Pressed");
  69. }
  70.  
  71. void loop(void)
  72. {
  73.     // Check if the button is pressed
  74.     if (digitalRead(buttonPin) == HIGH) {
  75.         lcd.clear(); // Clear the display
  76.         lcd.print("Button Pressed"); // Display message when button is pressed
  77.     } else {
  78.         lcd.clear(); // Clear the display
  79.         lcd.print("No Button Pressed"); // Display message when no button is pressed
  80.     }
  81.  
  82.     delay(100); // Small delay to avoid flickering
  83. }
  84.  
  85. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement