kelson8

Python LCD Code

Oct 4th, 2020 (edited)
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. import Adafruit_CharLCD as LCD
  2. import RPi.GPIO as GPIO # Import Raspberry Pi GPIO library
  3. from time import sleep
  4.  
  5. #Some code i use in my other python file to use the screen, found on a website
  6. # Raspberry Pi pin setup
  7. rs = 25
  8. en = 24
  9. d4 = 23
  10. d5 = 17
  11. d6 = 18
  12. d7 = 22
  13. backlight = 2
  14. #buttonPin=26
  15.  
  16. # Define LCD column and row size for 16x2 LCD.
  17. columns = 8
  18. rows = 1
  19. GPIO.setmode(GPIO.BCM)
  20. lcd = LCD.Adafruit_CharLCD(rs,en,d4,d5,d6, d7,columns,rows,backlight)
  21.  
  22. ####test##
  23.  
  24. GPIO.setmode(GPIO.BCM) #This is here twice, might remove one later
  25.  
  26. ## Code from raspberrypihq.com modified by Kelson
  27.  
  28. def button_callback(channel):
  29.     #print("Button was pushed!")
  30.     #Modified code prints "Hello!" in a scrolling fashion.. H clear e clear.. so on.
  31.     lcd.message("H")
  32.     lcd.clear()
  33.     lcd.message("e")
  34.     lcd.clear()
  35.     lcd.message("l")
  36.     lcd.clear()
  37.     lcd.message("l")
  38.     lcd.clear()
  39.     lcd.message("o")
  40.     lcd.clear()
  41.     lcd.message("!")
  42.  
  43. GPIO.setwarnings(False) # Ignore warning for now
  44.  
  45. GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) # Set pin 26 to be an input pin and set initial value to be pulled low (off)
  46.  
  47. GPIO.add_event_detect(26,GPIO.RISING,callback=button_callback) # Setup event on pin 10 rising edge
  48.  
  49. message = input("Press enter to quit\n\n") # Run until someone presses enter
  50.  
  51. GPIO.cleanup() # Clean up
  52. #lcd.clear()  #unused code
  53.  
Add Comment
Please, Sign In to add comment