This commit is contained in:
Benjamin Tayehanpour 2026-09-26 20:44:44 +00:00
parent b88fb8b436
commit 93ca674f93

28
LCD.py
View file

@ -42,14 +42,14 @@ class LCD:
raise ValueError('pi_rev param must be 1 or 2') raise ValueError('pi_rev param must be 1 or 2')
# Initialise display # Initialise display
await self.lcd_byte(0x33, self.LCD_CMD) # 110011 Initialise self.lcd_byte(0x33, self.LCD_CMD) # 110011 Initialise
await self.lcd_byte(0x32, self.LCD_CMD) # 110010 Initialise self.lcd_byte(0x32, self.LCD_CMD) # 110010 Initialise
await self.lcd_byte(0x06, self.LCD_CMD) # 000110 Cursor move direction self.lcd_byte(0x06, self.LCD_CMD) # 000110 Cursor move direction
await self.lcd_byte(0x0C, self.LCD_CMD) # 001100 Display On,Cursor Off, Blink Off self.lcd_byte(0x0C, self.LCD_CMD) # 001100 Display On,Cursor Off, Blink Off
await self.lcd_byte(0x28, self.LCD_CMD) # 101000 Data length, number of lines, font size self.lcd_byte(0x28, self.LCD_CMD) # 101000 Data length, number of lines, font size
await self.lcd_byte(0x01, self.LCD_CMD) # 000001 Clear display self.lcd_byte(0x01, self.LCD_CMD) # 000001 Clear display
async def lcd_byte(self, bits, mode): def lcd_byte(self, bits, mode):
# Send byte to data pins # Send byte to data pins
# bits = data # bits = data
# mode = 1 for data, 0 for command # mode = 1 for data, 0 for command
@ -59,18 +59,18 @@ class LCD:
# High bits # High bits
self.bus.write_byte(self.I2C_ADDR, bits_high) self.bus.write_byte(self.I2C_ADDR, bits_high)
await self.toggle_enable(bits_high) self.toggle_enable(bits_high)
# Low bits # Low bits
self.bus.write_byte(self.I2C_ADDR, bits_low) self.bus.write_byte(self.I2C_ADDR, bits_low)
await self.toggle_enable(bits_low) self.toggle_enable(bits_low)
async def toggle_enable(self, bits): def toggle_enable(self, bits):
await asyncio.sleep(self.E_DELAY) asyncio.sleep(self.E_DELAY)
self.bus.write_byte(self.I2C_ADDR, (bits | self.ENABLE)) self.bus.write_byte(self.I2C_ADDR, (bits | self.ENABLE))
await asyncio.sleep(self.E_PULSE) asyncio.sleep(self.E_PULSE)
self.bus.write_byte(self.I2C_ADDR,(bits & ~self.ENABLE)) self.bus.write_byte(self.I2C_ADDR,(bits & ~self.ENABLE))
await asyncio.sleep(self.E_DELAY) asyncio.sleep(self.E_DELAY)
async def async_message(self, string, line = 1): async def async_message(self, string, line = 1):
async with lock: async with lock:
@ -96,6 +96,6 @@ class LCD:
for i in range(self.LCD_WIDTH): for i in range(self.LCD_WIDTH):
self.lcd_byte(ord(string[i]), self.LCD_CHR) self.lcd_byte(ord(string[i]), self.LCD_CHR)
async def clear(self): def clear(self):
# clear LCD display # clear LCD display
self.lcd_byte(0x01, self.LCD_CMD) self.lcd_byte(0x01, self.LCD_CMD)