SHARE
TWEET

lcd

a guest Apr 21st, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from RPi import GPIO
  2.  
  3.  
  4. class LCD:
  5.     def __init__(self, isVierBits=False, E=20, RS=21, DB7=13, DB6=19, DB5=26, DB4=23, DB3=24, DB2=25, DB1= 12, DB0=16):
  6.         self.isVierBits = isVierBits
  7.         self.RS = RS
  8.         self.DB1 = DB1
  9.         self.DB0 = DB0
  10.         self.DB3 = DB3
  11.         self.E = E
  12.         self.DB2 = DB2
  13.         self.DB5 = DB5
  14.         self.DB4 = DB4
  15.         self.DB7 = DB7
  16.         self.DB6 = DB6
  17.         self.__shortDelay = 1/8
  18.         self.__longDelay = 1
  19.         self.__data_bits = [DB0, DB1, DB2, DB3, DB4, DB5, DB6, DB7]
  20.  
  21.     def __set_data_bits(self, value):
  22.         for v in range(value):
  23.             GPIO.output(self.E, 0)
  24.             GPIO.output(self.__data_bits[v], value >> v & 1)
  25.             GPIO.output(self.E, 1)
  26.  
  27.     def __send_instructions(self, value):
  28.         GPIO.output(self.RS, 0)
  29.         self.__set_data_bits(value)
  30.  
  31.     def send_character(self, value):
  32.         GPIO.output(self.RS, 1)
  33.         self.__set_data_bits(ord(str(value)))
  34.         print(ord(str(value)))
  35.  
  36.     def init_LCD(self):
  37.         self.initGPIO()
  38.         self.__send_instructions(0b00111000)
  39.         self.__send_instructions(0b00001111)
  40.         self.__send_instructions(0b00000001)
  41.  
  42.     def initGPIO(self):
  43.         GPIO.setmode(GPIO.BCM)
  44.         GPIO.setup(self.__data_bits, GPIO.OUT)
  45.         GPIO.setup(self.RS, GPIO.OUT)
  46.         GPIO.setup(self.E, GPIO.OUT)
  47.  
  48.     def write_message(self, value):
  49.         for i in value:
  50.             self.send_character(i)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top