25
25
26
26
TODO(description)
27
27
28
- * Author(s):
28
+ * Author(s):
29
29
-Brent Rubell
30
- -Asher Lieber
31
- -Tony DiCola for the original python charLCD library
30
+ -Asher Lieber
31
+ -Tony DiCola for the original python charLCD library
32
32
"""
33
33
34
34
"""
35
- `adafruit_character_lcd` - character lcd module
35
+ `adafruit_character_lcd` - character lcd module
36
36
=================================================
37
37
module for interfacing with character lcds
38
- """
39
- import time
38
+ """
39
+ import time
40
40
import math
41
41
import digitalio
42
42
from board import *
82
82
# Offset for up to 4 rows.
83
83
LCD_ROW_OFFSETS = (0x00 , 0x40 , 0x14 , 0x54 )
84
84
85
- class cirpyth_char_lcd (object ):
85
+ class Character_LCD (object ):
86
86
""" Interfaces with a character LCD
87
87
:param rs: The reset data line
88
88
:param en: The enable data line
@@ -93,13 +93,13 @@ class cirpyth_char_lcd(object):
93
93
:param enable_pwm: The PWM CONTROL, TODO
94
94
:param initial_backlight: THE initial backlight status (on/off)
95
95
"""
96
- def __init__ (self , rs , en , d4 , d5 , d6 , d7 , cols , lines ,
96
+ def __init__ (self , rs , en , d4 , d5 , d6 , d7 , cols , lines ,
97
97
backlight = None ,
98
98
enable_pwm = False ,
99
99
initial_backlight = 1.0 ):
100
100
101
101
self .cols = cols
102
- self .lines = lines
102
+ self .lines = lines
103
103
# save pin numbers
104
104
self .rs = rs
105
105
self .en = en
@@ -111,22 +111,22 @@ def __init__(self, rs, en, d4, d5, d6, d7, cols, lines,
111
111
self .backlight = backlight
112
112
# save backlight state
113
113
self .backlight = backlight
114
- self .pwn_enabled = enable_pwm
114
+ self .pwn_enabled = enable_pwm
115
115
# set all pins as outputs
116
116
for pin in (rs , en , d4 , d5 , d6 , d7 ):
117
117
pin .direction = digitalio .Direction .OUTPUT
118
- # Setup backlight
118
+ # Setup backlight
119
119
if backlight is not None :
120
120
self .backlight .direction = digitalio .Direction .OUTPUT
121
121
self .backlight .value = 0 # turn backlight on
122
- # initialize the display
122
+ # initialize the display
123
123
self ._write8 (0x33 )
124
124
self ._write8 (0x32 )
125
125
# init. display control
126
126
self .displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF
127
127
# init display function
128
128
self .displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_2LINE | LCD_5x8DOTS
129
- # init display mode
129
+ # init display mode
130
130
self .displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT
131
131
# write to display control
132
132
self ._write8 (LCD_DISPLAYCONTROL | self .displaycontrol )
@@ -157,11 +157,11 @@ def show_cursor(self, show):
157
157
def set_cursor (self , col , row ):
158
158
"""Sets the cursor to ``row`` and ``col``
159
159
:param col: column location
160
- :param row: row location
160
+ :param row: row location
161
161
"""
162
162
# Clamp row to the last row of the display
163
163
if row > self .lines :
164
- row = self .lines - 1
164
+ row = self .lines - 1
165
165
# Set location
166
166
self ._write8 (LCD_SETDDRAMADDR | (col + LCD_ROW_OFFSETS [row ]))
167
167
@@ -180,7 +180,7 @@ def move_left(self):
180
180
def move_right (self ):
181
181
"""Moves display right one position"""
182
182
self ._write8 (LCD_CURSORSHIFT | LCD_DISPLAYMOVE | LCD_MOVERIGHT )
183
-
183
+
184
184
def set_left_to_right (self ):
185
185
"""Set direction of text to read from left to right"""
186
186
self .displaymode |= LCD_ENTRYLEFT
@@ -202,7 +202,7 @@ def enable_display(self, enable):
202
202
def _write8 (self ,value , char_mode = False ):
203
203
"""Sends 8b ``value`` in ``char_mode``.
204
204
:param value: bytes
205
- :param char_mode: character/data mode selector. False (default) for
205
+ :param char_mode: character/data mode selector. False (default) for
206
206
data only, True for character bits.
207
207
"""
208
208
# one ms delay to prevent writing too quickly.
@@ -216,7 +216,7 @@ def _write8(self,value, char_mode = False):
216
216
self .d7 .value = ((value >> 7 ) & 1 ) > 0
217
217
# send command
218
218
self ._pulse_enable ()
219
- # WRITE lower 4 bits
219
+ # WRITE lower 4 bits
220
220
self .d4 .value = (value & 1 ) > 0
221
221
self .d5 .value = ((value >> 1 ) & 1 ) > 0
222
222
self .d6 .value = ((value >> 2 ) & 1 ) > 0
@@ -225,7 +225,7 @@ def _write8(self,value, char_mode = False):
225
225
226
226
def _pulse_enable (self ):
227
227
""" Pulses (lo->hi->lo) to send commands. """
228
- self .en .value = False
228
+ self .en .value = False
229
229
# 1microsec pause
230
230
time .sleep (0.0000001 )
231
231
self .en .value = True
@@ -240,7 +240,7 @@ def set_backlight(self, lighton):
240
240
else :
241
241
self .backlight .value = 1
242
242
243
-
243
+
244
244
def message (self , text ):
245
245
"""Write text to display, can include \n for newline"""
246
246
line = 0
@@ -252,7 +252,7 @@ def message(self, text):
252
252
# move to left/right depending on text direction
253
253
col = 0 if self .displaymode & LCD_ENTRYLEFT > 0 else self .cols - 1
254
254
self .set_cursor (col , line )
255
- # Write character to display
255
+ # Write character to display
256
256
else :
257
257
self ._write8 (ord (char ), True )
258
258
0 commit comments