Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanGallop authored May 16, 2020
1 parent 82ad2df commit 39327a4
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions RPi_GPIO_i2c_LCD/i2c_HD44780.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def write_block_data(self, cmd, data):
class lcd:
def __init__(self,address):
self.lcd = i2c(address)
##Backlight Status
self.bl = 0x08
self.write(0x03)
self.write(0x02)
self.write(0x20 | 0x08 | 0x00 | 0x00)
Expand All @@ -34,13 +36,13 @@ def __init__(self,address):
sleep(0.2)

def strobe(self, data):
self.lcd.write_cmd(data | 0b00000100 | 0x08)
self.lcd.write_cmd(data | 0b00000100 | self.bl)
sleep(.0005)
self.lcd.write_cmd(((data & ~0b00000100) | 0x08))
self.lcd.write_cmd(((data & ~0b00000100) | self.bl))
sleep(.0001)

def write_four_bits(self, data):
self.lcd.write_cmd(data | 0x08)
self.lcd.write_cmd(data | self.bl)
self.strobe(data)

def write(self, cmd, mode=0):
Expand All @@ -49,9 +51,9 @@ def write(self, cmd, mode=0):

def backlight(self, state):
if state.lower() == "on":
self.lcd.write_cmd(0x08)
self.bl=0x08
elif state.lower() == "off":
self.lcd.write_cmd(0x00)
self.bl=0x00

def display_string(self, string, line):
line_cmd = [0x00,0x80,0xC0,0x94,0xD4]
Expand All @@ -60,7 +62,10 @@ def display_string(self, string, line):
self.write(ord(char), 0b00000001)

def clear(self):
self.write(0x01)
self.write(0x03)
self.write(0x02)

self.write(0x20 | 0x08 | 0x00 | 0x00)
self.write(0x08 | 0x04)
self.write(0x01)
self.write(0x04 | 0x02)

0 comments on commit 39327a4

Please sign in to comment.