90
90
_LCD_5X8DOTS = const (0x00 )
91
91
92
92
# Offset for up to 4 rows.
93
- LCD_ROW_OFFSETS = (0x00 , 0x40 , 0x14 , 0x54 )
93
+ LCD_ROW_OFFSETS = (0x00 , 0x40 , 0x14 , 0x54 )
94
94
95
95
#pylint: enable-msg=bad-whitespace
96
96
@@ -117,9 +117,9 @@ class Character_LCD_RGB(object):
117
117
:param ~digitalio.DigitalInOut d7: The data line 7
118
118
:param cols: The columns on the charLCD
119
119
:param lines: The lines on the charLCD
120
- :param ~pulseio.PWMOut red: Red RGB Anode
121
- :param ~pulseio.PWMOut green: Green RGB Anode
122
- :param ~pulseio.PWMOut blue: Blue RGB Anode
120
+ :param ~pulseio.PWMOut, ~digitalio.DigitalInOut red: Red RGB Anode
121
+ :param ~pulseio.PWMOut, ~digitalio.DigitalInOut green: Green RGB Anode
122
+ :param ~pulseio.PWMOut, ~digitalio.DigitalInOut blue: Blue RGB Anode
123
123
:param ~digitalio.DigitalInOut backlight: The backlight pin, usually the last pin.
124
124
Consult the datasheet. Note that Pin value 0 means backlight is lit.
125
125
@@ -129,50 +129,57 @@ def __init__(self, rs, en, d4, d5, d6, d7, cols, lines,
129
129
red ,
130
130
green ,
131
131
blue ,
132
- backlight = None #,
133
- #enable_pwm = False,
134
- #initial_backlight = 1.0
132
+ backlight = None ,
133
+ enable_pwm = True
135
134
):
136
- # define columns and lines
137
135
self .cols = cols
138
136
self .lines = lines
139
- # define pin params
137
+
138
+ # define pin params
140
139
self .reset = rs
141
140
self .enable = en
142
141
self .dl4 = d4
143
142
self .dl5 = d5
144
143
self .dl6 = d6
145
144
self .dl7 = d7
146
- # define color params
147
- self .red = red
148
- self .green = green
149
- self .blue = blue
150
- # define rgb led
151
- self .rgb_led = [red , green , blue ]
145
+
152
146
# define backlight pin
153
147
self .backlight = backlight
154
- # self.pwn_enabled = enable_pwm
148
+ self .pwm_enabled = enable_pwm
149
+
155
150
# set all pins as outputs
156
151
for pin in (rs , en , d4 , d5 , d6 , d7 ):
157
152
pin .direction = digitalio .Direction .OUTPUT
158
- # setup backlight
153
+
154
+ # setup backlight
159
155
if backlight is not None :
160
156
self .backlight .direction = digitalio .Direction .OUTPUT
161
157
self .backlight .value = 0 # turn backlight on
162
- # initialize the display
158
+
159
+ # define color params
160
+ self .red = red
161
+ self .green = green
162
+ self .blue = blue
163
+ self .rgb_led = [red , green , blue ]
164
+
165
+ if not self .pwm_enabled :
166
+ for pin in self .rgb_led :
167
+ pin .direction = digitalio .Direction .OUTPUT
168
+
169
+ # initialize the display
163
170
self ._write8 (0x33 )
164
171
self ._write8 (0x32 )
165
- # init. display control
172
+ # init. display control
166
173
self .displaycontrol = _LCD_DISPLAYON | _LCD_CURSOROFF | _LCD_BLINKOFF
167
- # init display function
174
+ # init display function
168
175
self .displayfunction = _LCD_4BITMODE | _LCD_1LINE | _LCD_2LINE | _LCD_5X8DOTS
169
- # init display mode
176
+ # init display mode
170
177
self .displaymode = _LCD_ENTRYLEFT | _LCD_ENTRYSHIFTDECREMENT
171
- # write to display control
178
+ # write to display control
172
179
self ._write8 (_LCD_DISPLAYCONTROL | self .displaycontrol )
173
- # write displayfunction
180
+ # write displayfunction
174
181
self ._write8 (_LCD_FUNCTIONSET | self .displayfunction )
175
- # set the entry mode
182
+ # set the entry mode
176
183
self ._write8 (_LCD_ENTRYMODESET | self .displaymode )
177
184
self .clear ()
178
185
#pylint: enable-msg=too-many-arguments
@@ -259,25 +266,34 @@ def set_backlight(self, lighton):
259
266
self .backlight .value = 1
260
267
261
268
def set_color (self , color ):
262
- """ Method to set the duty cycle of the RGB LED
263
- :param color: list of 3 integers in range(100). ``[R,G,B]`` 0 is no
264
- color, 100 it maximum color
269
+ """Method to set the duty cycle or the on/off value of the RGB LED
270
+ :param color: list of 3 integers in range(100). ``[R,G,B]`` 0 is no
271
+ color, 100 is maximum color. If PWM is disabled, 0 is off and
272
+ non-zero is on.
265
273
"""
266
- self .rgb_led [0 ].duty_cycle = int (_map (color [0 ], 0 , 100 , 65535 , 0 ))
267
- self .rgb_led [1 ].duty_cycle = int (_map (color [1 ], 0 , 100 , 65535 , 0 ))
268
- self .rgb_led [2 ].duty_cycle = int (_map (color [2 ], 0 , 100 , 65535 , 0 ))
274
+ if self .pwm_enabled :
275
+ self .rgb_led [0 ].duty_cycle = int (_map (color [0 ], 0 , 100 , 65535 , 0 ))
276
+ self .rgb_led [1 ].duty_cycle = int (_map (color [1 ], 0 , 100 , 65535 , 0 ))
277
+ self .rgb_led [2 ].duty_cycle = int (_map (color [2 ], 0 , 100 , 65535 , 0 ))
278
+ else :
279
+ # If we don't have PWM enabled, all we can do is turn each color
280
+ # on / off. Assume a DigitalInOut and write 0 (on) to pin for any
281
+ # value greater than 0, or 1 (off) for 0:
282
+ self .rgb_led [0 ].value = 0 if color [0 ] > 0 else 1
283
+ self .rgb_led [1 ].value = 0 if color [1 ] > 0 else 1
284
+ self .rgb_led [2 ].value = 0 if color [2 ] > 0 else 1
269
285
270
286
def message (self , text ):
271
287
"""Write text to display, can include \n for newline
272
288
:param text: string to display
273
289
"""
274
290
line = 0
275
- # iterate thru each char
291
+ # iterate thru each char
276
292
for char in text :
277
293
# if character is \n, go to next line
278
294
if char == '\n ' :
279
295
line += 1
280
- # move to left/right depending on text direction
296
+ # move to left/right depending on text direction
281
297
col = 0 if self .displaymode & _LCD_ENTRYLEFT > 0 else self .cols - 1
282
298
self .set_cursor (col , line )
283
299
# Write character to display
0 commit comments