Skip to content

Commit 849d352

Browse files
authored
Merge pull request #51 from taotien/master
Update charlcd_rpi_rgb_simpletest.py example with new support for PWM control of RGB backlight
2 parents ef64ef7 + 961d9c6 commit 849d352

File tree

2 files changed

+85
-40
lines changed

2 files changed

+85
-40
lines changed

adafruit_character_lcd/character_lcd.py

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -547,18 +547,18 @@ def _pulse_enable(self):
547547
class Character_LCD_Mono(Character_LCD):
548548
"""Interfaces with monochromatic character LCDs.
549549
550-
:param ~digitalio.DigitalInOut rs: The reset data line
551-
:param ~digitalio.DigitalInOut en: The enable data line
552-
:param ~digitalio.DigitalInOut d4: The data line 4
553-
:param ~digitalio.DigitalInOut d5: The data line 5
554-
:param ~digitalio.DigitalInOut d6: The data line 6
555-
:param ~digitalio.DigitalInOut d7: The data line 7
556-
:param columns: The columns on the charLCD
557-
:param lines: The lines on the charLCD
558-
:param ~digitalio.DigitalInOut backlight_pin: The backlight pin
559-
:param bool backlight_inverted: ``False`` if LCD is not inverted, i.e. backlight pin is
560-
connected to common anode. ``True`` if LCD is inverted i.e. backlight pin is connected
561-
to common cathode.
550+
:param ~digitalio.DigitalInOut rs: The reset data line
551+
:param ~digitalio.DigitalInOut en: The enable data line
552+
:param ~digitalio.DigitalInOut d4: The data line 4
553+
:param ~digitalio.DigitalInOut d5: The data line 5
554+
:param ~digitalio.DigitalInOut d6: The data line 6
555+
:param ~digitalio.DigitalInOut d7: The data line 7
556+
:param columns: The columns on the charLCD
557+
:param lines: The lines on the charLCD
558+
:param ~digitalio.DigitalInOut backlight_pin: The backlight pin
559+
:param bool backlight_inverted: ``False`` if LCD is not inverted, i.e. backlight pin is
560+
connected to common anode. ``True`` if LCD is inverted i.e. backlight pin is connected
561+
to common cathode.
562562
563563
"""
564564

@@ -629,19 +629,19 @@ def backlight(self, enable):
629629
class Character_LCD_RGB(Character_LCD):
630630
"""Interfaces with RGB character LCDs.
631631
632-
:param ~digitalio.DigitalInOut rs: The reset data line
633-
:param ~digitalio.DigitalInOut en: The enable data line
634-
:param ~digitalio.DigitalInOut db4: The data line 4
635-
:param ~digitalio.DigitalInOut db5: The data line 5
636-
:param ~digitalio.DigitalInOut db6: The data line 6
637-
:param ~digitalio.DigitalInOut db7: The data line 7
638-
:param columns: The columns on the charLCD
639-
:param lines: The lines on the charLCD
640-
:param ~pulseio.PWMOut, ~digitalio.DigitalInOut red: Red RGB Anode
641-
:param ~pulseio.PWMOut, ~digitalio.DigitalInOut green: Green RGB Anode
642-
:param ~pulseio.PWMOut, ~digitalio.DigitalInOut blue: Blue RGB Anode
643-
:param ~digitalio.DigitalInOut read_write: The rw pin. Determines whether to read to or
644-
write from the display. Not necessary if only writing to the display. Used on shield.
632+
:param ~digitalio.DigitalInOut rs: The reset data line
633+
:param ~digitalio.DigitalInOut en: The enable data line
634+
:param ~digitalio.DigitalInOut db4: The data line 4
635+
:param ~digitalio.DigitalInOut db5: The data line 5
636+
:param ~digitalio.DigitalInOut db6: The data line 6
637+
:param ~digitalio.DigitalInOut db7: The data line 7
638+
:param columns: The columns on the charLCD
639+
:param lines: The lines on the charLCD
640+
:param ~pulseio.PWMOut, ~digitalio.DigitalInOut red: Red RGB Anode
641+
:param ~pulseio.PWMOut, ~digitalio.DigitalInOut green: Green RGB Anode
642+
:param ~pulseio.PWMOut, ~digitalio.DigitalInOut blue: Blue RGB Anode
643+
:param ~digitalio.DigitalInOut read_write: The rw pin. Determines whether to read to or
644+
write from the display. Not necessary if only writing to the display. Used on shield.
645645
646646
"""
647647

examples/charlcd_rpi_rgb_simpletest.py

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import time
33
import board
44
import digitalio
5+
import pulseio
56
import adafruit_character_lcd.character_lcd as characterlcd
67

78
# Modify this if you have a different sized character LCD
@@ -15,11 +16,10 @@
1516
lcd_d6 = digitalio.DigitalInOut(board.D22) # pin 13
1617
lcd_d5 = digitalio.DigitalInOut(board.D24) # pin 12
1718
lcd_d4 = digitalio.DigitalInOut(board.D25) # pin 11
18-
lcd_backlight = digitalio.DigitalInOut(board.D4)
1919

20-
red = digitalio.DigitalInOut(board.D21)
21-
green = digitalio.DigitalInOut(board.D12)
22-
blue = digitalio.DigitalInOut(board.D18)
20+
red = pulseio.PWMOut(board.D21)
21+
green = pulseio.PWMOut(board.D12)
22+
blue = pulseio.PWMOut(board.D18)
2323

2424
# Initialise the LCD class
2525
lcd = characterlcd.Character_LCD_RGB(
@@ -34,25 +34,70 @@
3434
red,
3535
green,
3636
blue,
37-
lcd_backlight,
3837
)
3938

40-
RED = [1, 0, 0]
41-
GREEN = [0, 1, 0]
42-
BLUE = [0, 0, 1]
39+
RED = [100, 0, 0]
40+
GREEN = [0, 100, 0]
41+
BLUE = [0, 0, 100]
4342

4443
while True:
4544
lcd.clear()
46-
lcd.message = "CircuitPython\nRGB Test: RED"
47-
lcd.color = RED
45+
# Set LCD color to red
46+
lcd.color = [100, 0, 0]
4847
time.sleep(1)
4948

50-
lcd.clear()
51-
lcd.message = "CircuitPython\nRGB Test: GREEN"
52-
lcd.color = GREEN
49+
# Print two line message
50+
lcd.message = "Hello\nCircuitPython"
51+
52+
# Wait 5s
53+
time.sleep(5)
54+
55+
# Set LCD color to blue
56+
lcd.color = [0, 100, 0]
57+
time.sleep(1)
58+
# Set LCD color to green
59+
lcd.color = [0, 0, 100]
5360
time.sleep(1)
61+
# Set LCD color to purple
62+
lcd.color = [50, 0, 50]
63+
time.sleep(1)
64+
lcd.clear()
65+
66+
# Print two line message right to left
67+
lcd.text_direction = lcd.RIGHT_TO_LEFT
68+
lcd.message = "Hello\nCircuitPython"
69+
# Wait 5s
70+
time.sleep(5)
71+
72+
# Return text direction to left to right
73+
lcd.text_direction = lcd.LEFT_TO_RIGHT
74+
75+
# Display cursor
76+
lcd.clear()
77+
lcd.cursor = True
78+
lcd.message = "Cursor! "
79+
# Wait 5s
80+
time.sleep(5)
81+
82+
# Display blinking cursor
83+
lcd.clear()
84+
lcd.blink = True
85+
lcd.message = "Blinky Cursor!"
86+
# Wait 5s
87+
time.sleep(5)
88+
lcd.blink = False
89+
lcd.clear()
90+
91+
# Create message to scroll
92+
scroll_msg = "<-- Scroll"
93+
lcd.message = scroll_msg
94+
# Scroll to the left
95+
for i in range(len(scroll_msg)):
96+
time.sleep(0.5)
97+
lcd.move_left()
98+
lcd.clear()
5499

100+
# Turn off LCD backlights and clear text
101+
lcd.color = [0, 0, 0]
55102
lcd.clear()
56-
lcd.message = "CircuitPython\nRGB Test: BLUE"
57-
lcd.color = BLUE
58103
time.sleep(1)

0 commit comments

Comments
 (0)