def __init__(self, lcd_address, lcd_width):
# Define some device parameters
self.I2C_ADDR = lcd_address # 0x3f I2C device address
# To detect use sudo i2cdetect -y 0
# or for RPi 2 sudo i2cdetect -y 1
self.LCD_WIDTH = lcd_width # 16 or 20 Maximum characters per line
print ("class LCD " + str(lcd_width))
#LCD_WIDTH = 20 OR 16 # Maximum characters per line
# Define some device constants
self.LCD_CHR = 1 # Mode - Sending data
self.LCD_CMD = 0 # Mode - Sending command
self.LCD_LINE_1 = 0x80 # LCD RAM address for the 1st line
self.LCD_LINE_2 = 0xC0 # LCD RAM address for the 2nd line
self.LCD_LINE_3 = 0x94 # LCD RAM address for the 3rd line
self.LCD_LINE_4 = 0xD4 # LCD RAM address for the 4th line
self.LCD_BACKLIGHT = 0x08 # On
#LCD_BACKLIGHT = 0x00 # Off
self.ENABLE = 0b00000100 # Enable bit
# Timing constants
self.E_PULSE = 0.0005
self.E_DELAY = 0.0005
#Open I2C interface
self.bus = smbus.SMBus(0) # Rev 1 Pi uses 0
#bus = smbus.SMBus(1) # Rev 2 Pi uses 1
#def lcd_init():
# Initialise display
self.lcd_byte(0x33,self.LCD_CMD) # 110011 Initialise
self.lcd_byte(0x32,self.LCD_CMD) # 110010 Initialise
self.lcd_byte(0x06,self.LCD_CMD) # 000110 Cursor move direction
self.lcd_byte(0x0C,self.LCD_CMD) # 001100 Display On,Cursor Off, Blink Off
self.lcd_byte(0x28,self.LCD_CMD) # 101000 Data length, number of lines, font size
self.lcd_byte(0x01,self.LCD_CMD) # 000001 Clear display
time.sleep(self.E_DELAY)
评论列表
文章目录