LCD
This commit is contained in:
parent
c4f60a9cf8
commit
b0b4012973
4 changed files with 22 additions and 12 deletions
|
|
@ -1,12 +1,14 @@
|
|||
import asyncio
|
||||
import smbus
|
||||
import time
|
||||
|
||||
lock = asyncio.lock()
|
||||
|
||||
class LCD:
|
||||
def __init__(self, pi_rev = 2, i2c_addr = 0x3F, backlight = True):
|
||||
async def __init__(self, pi_rev = 2, i2c_addr = 0x3F, backlight = True):
|
||||
|
||||
# device constants
|
||||
self.I2C_ADDR = i2c_addr
|
||||
self.LCD_WIDTH = 16 # Max. characters per line
|
||||
self.LCD_WIDTH = 20 # Max. characters per line
|
||||
|
||||
self.LCD_CHR = 1 # Mode - Sending data
|
||||
self.LCD_CMD = 0 # Mode - Sending command
|
||||
|
|
@ -47,7 +49,7 @@ class LCD:
|
|||
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
|
||||
|
||||
def lcd_byte(self, bits, mode):
|
||||
async def lcd_byte(self, bits, mode):
|
||||
# Send byte to data pins
|
||||
# bits = data
|
||||
# mode = 1 for data, 0 for command
|
||||
|
|
@ -63,14 +65,18 @@ class LCD:
|
|||
self.bus.write_byte(self.I2C_ADDR, bits_low)
|
||||
self.toggle_enable(bits_low)
|
||||
|
||||
def toggle_enable(self, bits):
|
||||
time.sleep(self.E_DELAY)
|
||||
async def toggle_enable(self, bits):
|
||||
await asyncio.sleep(self.E_DELAY)
|
||||
self.bus.write_byte(self.I2C_ADDR, (bits | self.ENABLE))
|
||||
time.sleep(self.E_PULSE)
|
||||
await asyncio.sleep(self.E_PULSE)
|
||||
self.bus.write_byte(self.I2C_ADDR,(bits & ~self.ENABLE))
|
||||
time.sleep(self.E_DELAY)
|
||||
await asyncio.sleep(self.E_DELAY)
|
||||
|
||||
async def async_message(self, string, line = 1):
|
||||
async with lock:
|
||||
result = await asyncio.to_thread(_message, string = string, line = line)
|
||||
|
||||
def message(self, string, line = 1):
|
||||
def _message(self, string, line = 1):
|
||||
# display message string on indicated LCD line
|
||||
if line == 1:
|
||||
lcd_line = self.LCD_LINE_1
|
||||
|
|
@ -90,6 +96,6 @@ class LCD:
|
|||
for i in range(self.LCD_WIDTH):
|
||||
self.lcd_byte(ord(string[i]), self.LCD_CHR)
|
||||
|
||||
def clear(self):
|
||||
async def clear(self):
|
||||
# clear LCD display
|
||||
self.lcd_byte(0x01, self.LCD_CMD)
|
||||
3
LICENSE
3
LICENSE
|
|
@ -1,6 +1,7 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2026 sa0tay
|
||||
Copyright (c) 2026 Benjamin Tayehanpour
|
||||
LCD.py based on code (c) 2018 Sterling Beason, also MIT
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import asyncio
|
||||
|
||||
import asyncpio
|
||||
|
||||
class decoder:
|
||||
|
|
|
|||
4
fancontrol.py
Normal file
4
fancontrol.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import asyncio
|
||||
from decoder import decoder
|
||||
from display import display
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue