Skip to content

Commit

Permalink
Merge pull request #51 from taotien/master
Browse files Browse the repository at this point in the history
Update charlcd_rpi_rgb_simpletest.py example with new support for PWM control of RGB backlight
  • Loading branch information
evaherrada authored Nov 13, 2020
2 parents ef64ef7 + 961d9c6 commit 849d352
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 40 deletions.
50 changes: 25 additions & 25 deletions adafruit_character_lcd/character_lcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,18 +547,18 @@ def _pulse_enable(self):
class Character_LCD_Mono(Character_LCD):
"""Interfaces with monochromatic character LCDs.
:param ~digitalio.DigitalInOut rs: The reset data line
:param ~digitalio.DigitalInOut en: The enable data line
:param ~digitalio.DigitalInOut d4: The data line 4
:param ~digitalio.DigitalInOut d5: The data line 5
:param ~digitalio.DigitalInOut d6: The data line 6
:param ~digitalio.DigitalInOut d7: The data line 7
:param columns: The columns on the charLCD
:param lines: The lines on the charLCD
:param ~digitalio.DigitalInOut backlight_pin: The backlight pin
:param bool backlight_inverted: ``False`` if LCD is not inverted, i.e. backlight pin is
connected to common anode. ``True`` if LCD is inverted i.e. backlight pin is connected
to common cathode.
:param ~digitalio.DigitalInOut rs: The reset data line
:param ~digitalio.DigitalInOut en: The enable data line
:param ~digitalio.DigitalInOut d4: The data line 4
:param ~digitalio.DigitalInOut d5: The data line 5
:param ~digitalio.DigitalInOut d6: The data line 6
:param ~digitalio.DigitalInOut d7: The data line 7
:param columns: The columns on the charLCD
:param lines: The lines on the charLCD
:param ~digitalio.DigitalInOut backlight_pin: The backlight pin
:param bool backlight_inverted: ``False`` if LCD is not inverted, i.e. backlight pin is
connected to common anode. ``True`` if LCD is inverted i.e. backlight pin is connected
to common cathode.
"""

Expand Down Expand Up @@ -629,19 +629,19 @@ def backlight(self, enable):
class Character_LCD_RGB(Character_LCD):
"""Interfaces with RGB character LCDs.
:param ~digitalio.DigitalInOut rs: The reset data line
:param ~digitalio.DigitalInOut en: The enable data line
:param ~digitalio.DigitalInOut db4: The data line 4
:param ~digitalio.DigitalInOut db5: The data line 5
:param ~digitalio.DigitalInOut db6: The data line 6
:param ~digitalio.DigitalInOut db7: The data line 7
:param columns: The columns on the charLCD
:param lines: The lines on the charLCD
:param ~pulseio.PWMOut, ~digitalio.DigitalInOut red: Red RGB Anode
:param ~pulseio.PWMOut, ~digitalio.DigitalInOut green: Green RGB Anode
:param ~pulseio.PWMOut, ~digitalio.DigitalInOut blue: Blue RGB Anode
:param ~digitalio.DigitalInOut read_write: The rw pin. Determines whether to read to or
write from the display. Not necessary if only writing to the display. Used on shield.
:param ~digitalio.DigitalInOut rs: The reset data line
:param ~digitalio.DigitalInOut en: The enable data line
:param ~digitalio.DigitalInOut db4: The data line 4
:param ~digitalio.DigitalInOut db5: The data line 5
:param ~digitalio.DigitalInOut db6: The data line 6
:param ~digitalio.DigitalInOut db7: The data line 7
:param columns: The columns on the charLCD
:param lines: The lines on the charLCD
:param ~pulseio.PWMOut, ~digitalio.DigitalInOut red: Red RGB Anode
:param ~pulseio.PWMOut, ~digitalio.DigitalInOut green: Green RGB Anode
:param ~pulseio.PWMOut, ~digitalio.DigitalInOut blue: Blue RGB Anode
:param ~digitalio.DigitalInOut read_write: The rw pin. Determines whether to read to or
write from the display. Not necessary if only writing to the display. Used on shield.
"""

Expand Down
75 changes: 60 additions & 15 deletions examples/charlcd_rpi_rgb_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import time
import board
import digitalio
import pulseio
import adafruit_character_lcd.character_lcd as characterlcd

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

red = digitalio.DigitalInOut(board.D21)
green = digitalio.DigitalInOut(board.D12)
blue = digitalio.DigitalInOut(board.D18)
red = pulseio.PWMOut(board.D21)
green = pulseio.PWMOut(board.D12)
blue = pulseio.PWMOut(board.D18)

# Initialise the LCD class
lcd = characterlcd.Character_LCD_RGB(
Expand All @@ -34,25 +34,70 @@
red,
green,
blue,
lcd_backlight,
)

RED = [1, 0, 0]
GREEN = [0, 1, 0]
BLUE = [0, 0, 1]
RED = [100, 0, 0]
GREEN = [0, 100, 0]
BLUE = [0, 0, 100]

while True:
lcd.clear()
lcd.message = "CircuitPython\nRGB Test: RED"
lcd.color = RED
# Set LCD color to red
lcd.color = [100, 0, 0]
time.sleep(1)

lcd.clear()
lcd.message = "CircuitPython\nRGB Test: GREEN"
lcd.color = GREEN
# Print two line message
lcd.message = "Hello\nCircuitPython"

# Wait 5s
time.sleep(5)

# Set LCD color to blue
lcd.color = [0, 100, 0]
time.sleep(1)
# Set LCD color to green
lcd.color = [0, 0, 100]
time.sleep(1)
# Set LCD color to purple
lcd.color = [50, 0, 50]
time.sleep(1)
lcd.clear()

# Print two line message right to left
lcd.text_direction = lcd.RIGHT_TO_LEFT
lcd.message = "Hello\nCircuitPython"
# Wait 5s
time.sleep(5)

# Return text direction to left to right
lcd.text_direction = lcd.LEFT_TO_RIGHT

# Display cursor
lcd.clear()
lcd.cursor = True
lcd.message = "Cursor! "
# Wait 5s
time.sleep(5)

# Display blinking cursor
lcd.clear()
lcd.blink = True
lcd.message = "Blinky Cursor!"
# Wait 5s
time.sleep(5)
lcd.blink = False
lcd.clear()

# Create message to scroll
scroll_msg = "<-- Scroll"
lcd.message = scroll_msg
# Scroll to the left
for i in range(len(scroll_msg)):
time.sleep(0.5)
lcd.move_left()
lcd.clear()

# Turn off LCD backlights and clear text
lcd.color = [0, 0, 0]
lcd.clear()
lcd.message = "CircuitPython\nRGB Test: BLUE"
lcd.color = BLUE
time.sleep(1)

0 comments on commit 849d352

Please sign in to comment.