Advertisement
microrobotics

Character Display - LCD 2X16 - 5V - White on Black (HD44780)

May 10th, 2023
1,106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. To interface with a HD44780 parallel interface LCD, you can use the LiquidCrystal library that comes with the Arduino IDE.
  3.  
  4. This example uses a 4-bit interface, meaning it sends data 4 bits at a time. It connects the LCD RS, E, and data lines (D4-D7) to the Arduino digital pins. It uses the LiquidCrystal(rs, enable, d4, d5, d6, d7) function to initialize the library.
  5.  
  6. In the setup() function, it calls lcd.begin(16, 2) to set up the LCD's number of columns and rows. It then prints "Hello, World!" to the first line of the display.
  7.  
  8. The loop() function sets the cursor to the beginning of the second line with lcd.setCursor(0, 1) and then prints the number of seconds since the Arduino was last reset.
  9.  
  10. Make sure to replace the pin numbers in the LiquidCrystal lcd(rs, en, d4, d5, d6, d7); line with the actual pin numbers you're using.
  11.  
  12. Here is a simple example of how to display "Hello, World!" on a 2x16 LCD:
  13. */
  14.  
  15. #include <LiquidCrystal.h>
  16.  
  17. // Initialize the library by associating any needed LCD interface pin
  18. // with the arduino pin number it is connected to
  19. const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
  20. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  21.  
  22. void setup() {
  23.   // set up the LCD's number of columns and rows:
  24.   lcd.begin(16, 2);
  25.   // Print a message to the LCD
  26.   lcd.print("Hello, World!");
  27. }
  28.  
  29. void loop() {
  30.   // set the cursor to column 0, line 1
  31.   lcd.setCursor(0, 1);
  32.   // print the number of seconds since reset:
  33.   lcd.print(millis() / 1000);
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement