Adding keypad support and example

This commit is contained in:
Kattni Rembor 2019-01-13 17:55:03 -05:00
parent 281bd43e42
commit 352d7c6626
3 changed files with 173 additions and 1 deletions

View file

@ -34,10 +34,13 @@ Implementation Notes
"* `RGB LCD Shield Kit w/ 16x2 Character Display - Negative Display
<https://www.adafruit.com/product/714>`_"
"* `RGB LCD Shield Kit w/ 16x2 Character Display - Positive Display
<https://www.adafruit.com/product/716>`_"
"* `Adafruit RGB Negative 16x2 LCD+Keypad Kit for Raspberry Pi
<https://www.adafruit.com/product/1110>`_"
"* `Adafruit RGB Positive 16x2 LCD+Keypad Kit for Raspberry Pi
<https://www.adafruit.com/product/1109>`_"
@ -50,9 +53,10 @@ Implementation Notes
"""
import digitalio
from adafruit_character_lcd.character_lcd import Character_LCD_RGB
__version__ = "0.0.0-auto.0"
__version__ = "3.0.3"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CharLCD.git"
@ -91,5 +95,127 @@ class Character_LCD_RGB_I2C(Character_LCD_RGB):
red = self._mcp.get_pin(6)
green = self._mcp.get_pin(7)
blue = self._mcp.get_pin(8)
self._left_button = self._mcp.get_pin(4)
self._up_button = self._mcp.get_pin(3)
self._down_button = self._mcp.get_pin(2)
self._right_button = self._mcp.get_pin(1)
self._select_button = self._mcp.get_pin(0)
self._buttons = [self._left_button, self._up_button, self._down_button, self._right_button,
self._select_button]
for pin in self._buttons:
pin.switch_to_input(pull=digitalio.Pull.UP)
super().__init__(reset, enable, db4, db5, db6, db7, columns, lines, red, green, blue,
read_write)
@property
def left_button(self):
"""The left button on the RGB Character LCD I2C Shield or Pi plate.
The following example prints "Left!" to the LCD when the left button is pressed:
.. code-block:: python
import board
import busio
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C
i2c = busio.I2C(board.SCL, board.SDA)
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)
while True:
if lcd.left_button:
lcd.message = "Left!"
"""
return not self._left_button.value
@property
def up_button(self):
"""The up button on the RGB Character LCD I2C Shield or Pi plate.
The following example prints "Up!" to the LCD when the up button is pressed:
.. code-block:: python
import board
import busio
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C
i2c = busio.I2C(board.SCL, board.SDA)
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)
while True:
if lcd.up_button:
lcd.message = "Up!"
"""
return not self._up_button.value
@property
def down_button(self):
"""The down button on the RGB Character LCD I2C Shield or Pi plate.
The following example prints "Down!" to the LCD when the down button is pressed:
.. code-block:: python
import board
import busio
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C
i2c = busio.I2C(board.SCL, board.SDA)
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)
while True:
if lcd.down_button:
lcd.message = "Down!"
"""
return not self._down_button.value
@property
def right_button(self):
"""The right button on the RGB Character LCD I2C Shield or Pi plate.
The following example prints "Right!" to the LCD when the right button is pressed:
.. code-block:: python
import board
import busio
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C
i2c = busio.I2C(board.SCL, board.SDA)
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)
while True:
if lcd.right_button:
lcd.message = "Right!"
"""
return not self._right_button.value
@property
def select_button(self):
"""The select button on the RGB Character LCD I2C Shield or Pi plate.
The following example prints "Select!" to the LCD when the select button is pressed:
.. code-block:: python
import board
import busio
from adafruit_character_lcd.character_lcd_rgb_i2c import Character_LCD_RGB_I2C
i2c = busio.I2C(board.SCL, board.SDA)
lcd = Character_LCD_RGB_I2C(i2c, 16, 2)
while True:
if lcd.select_button:
lcd.message = "Select!"
"""
return not self._select_button.value

View file

@ -18,3 +18,7 @@ Ensure your device works with this simple test.
.. literalinclude:: ../examples/charlcd_spi_mono_simpletest.py
:caption: examples/charlcd_spi_mono_simpletest.py
:linenos:
.. literalinclude:: ../examples/charlcd_keypad_simpletest.py
:caption: examples/charlcd_keypad_simpletest.py
:linenos:

View file

@ -0,0 +1,42 @@
"""Simple test for keypad on I2C RGB character LCD Shield or Pi Plate kits"""
import time
import board
import busio
import adafruit_character_lcd.character_lcd_rgb_i2c as character_lcd
# Modify this if you have a different sized Character LCD
lcd_columns = 16
lcd_rows = 2
# Initialise I2C bus.
i2c = busio.I2C(board.SCL, board.SDA)
# Initialise the LCD class
lcd = character_lcd.Character_LCD_RGB_I2C(i2c, lcd_columns, lcd_rows)
lcd.clear()
lcd.color = [100, 0, 0]
while True:
if lcd.left_button:
print("Left!")
lcd.message = "Left!"
if lcd.up_button:
print("Up!")
lcd.message = "Up!"
if lcd.down_button:
print("Down!")
lcd.message = "Down!"
if lcd.right_button:
print("Right!")
lcd.message = "Right!"
if lcd.select_button:
print("Select!")
lcd.message = "Select!"
else:
time.sleep(0.1)
lcd.clear()