Advertisement
pleasedontcode

"LCD Keypresses" rev_01

May 27th, 2024
815
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 Keypresses"
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-05-27 23:15:56
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Create a system to interface an Arduino with an */
  21.     /* LCD1602 display using the LiquidCrystal library. */
  22.     /* Configure digital output pins (D4, D13, D14, D16, */
  23.     /* D17, D18) for LCD control and ensure real-time */
  24.     /* updates of key press data on the screen. */
  25. /****** SYSTEM REQUIREMENT 2 *****/
  26.     /* code will emulate a keyboard stroke and send it to */
  27.     /* pc as keyboard click */
  28. /****** END SYSTEM REQUIREMENTS *****/
  29.  
  30. /****** DEFINITION OF LIBRARIES *****/
  31. #include <LiquidCrystal.h>
  32. #include <Keyboard.h>
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t mylcd_LCD1602_RS_PIN_D4 = 4;
  40. const uint8_t mylcd_LCD1602_E_PIN_D13 = 13;
  41. const uint8_t mylcd_LCD1602_D4_PIN_D14 = 14;
  42. const uint8_t mylcd_LCD1602_D5_PIN_D16 = 16;
  43. const uint8_t mylcd_LCD1602_D6_PIN_D17 = 17;
  44. const uint8_t mylcd_LCD1602_D7_PIN_D18 = 18;
  45.  
  46. /***** INSTANTIATE LCD OBJECT *****/
  47. LiquidCrystal lcd(mylcd_LCD1602_RS_PIN_D4, mylcd_LCD1602_E_PIN_D13, mylcd_LCD1602_D4_PIN_D14, mylcd_LCD1602_D5_PIN_D16, mylcd_LCD1602_D6_PIN_D17, mylcd_LCD1602_D7_PIN_D18);
  48.  
  49. void setup(void)
  50. {
  51.     // Initialize the LCD and set up the number of columns and rows
  52.     lcd.begin(16, 2);
  53.     lcd.print("Hello, World!");
  54.  
  55.     // Initialize the keyboard
  56.     Keyboard.begin();
  57.  
  58.     // Set pin modes
  59.     pinMode(mylcd_LCD1602_RS_PIN_D4, OUTPUT);
  60.     pinMode(mylcd_LCD1602_E_PIN_D13, OUTPUT);
  61.     pinMode(mylcd_LCD1602_D4_PIN_D14, OUTPUT);
  62.     pinMode(mylcd_LCD1602_D5_PIN_D16, OUTPUT);
  63.     pinMode(mylcd_LCD1602_D6_PIN_D17, OUTPUT);
  64.     pinMode(mylcd_LCD1602_D7_PIN_D18, OUTPUT);
  65. }
  66.  
  67. void loop(void)
  68. {
  69.     // Check for key press and update the LCD
  70.     if (Serial.available() > 0) {
  71.         char key = Serial.read();
  72.         lcd.clear();
  73.         lcd.print("Key Pressed: ");
  74.         lcd.print(key);
  75.  
  76.         // Emulate keyboard stroke
  77.         Keyboard.write(key);
  78.     }
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement