Advertisement
pleasedontcode

LCD Control rev_01

Oct 21st, 2024
93
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: LCD Control
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-10-21 16:39:30
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* When you press the key, the LED turns on */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Wire.h>
  25. #include <LiquidCrystal_I2C.h>  //https://github.com/marcoschwartz/LiquidCrystal_I2C
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF I2C PINS *****/
  32. const uint8_t Lcd_LCD1602I2C_I2C_PIN_SDA_A4     = A4;
  33. const uint8_t Lcd_LCD1602I2C_I2C_PIN_SCL_A5     = A5;
  34. const uint8_t Lcd_LCD1602I2C_I2C_SLAVE_ADDRESS      = 39;
  35.  
  36. /***** DEFINITION OF LED PIN *****/
  37. const uint8_t LED_PIN = 13; // Define the pin for the LED
  38.  
  39. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  40. // Initialize the LiquidCrystal_I2C object with the I2C address and dimensions
  41. LiquidCrystal_I2C lcd(Lcd_LCD1602I2C_I2C_SLAVE_ADDRESS, 20, 4); // 20 columns and 4 rows
  42.  
  43. void setup(void)
  44. {
  45.     // Initialize the LCD
  46.     lcd.init(); // Initialize the LCD
  47.     lcd.backlight(); // Turn on the backlight
  48.     Serial.begin(9600); // Start serial communication at 9600 baud rate
  49.    
  50.     // Initialize the LED pin as an output
  51.     pinMode(LED_PIN, OUTPUT); // Set LED pin as output
  52. }
  53.  
  54. void loop(void)
  55. {
  56.     // Check if there is any data available to read from the serial port
  57.     if (Serial.available())
  58.     {
  59.         delay(100); // Short delay to allow data to be fully received
  60.         lcd.clear(); // Clear the LCD display
  61.         while (Serial.available() > 0) // While there is data available
  62.         {
  63.             lcd.write(Serial.read()); // Read and display each character on the LCD
  64.         }
  65.        
  66.         // Turn on the LED when a key is pressed
  67.         digitalWrite(LED_PIN, HIGH); // Turn on the LED
  68.         delay(1000); // Keep the LED on for 1 second
  69.         digitalWrite(LED_PIN, LOW); // Turn off the LED
  70.     }
  71. }
  72.  
  73. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement