From 352d7c6626630f30751b4ce10b01ee8bde53adc6 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Sun, 13 Jan 2019 17:55:03 -0500 Subject: [PATCH 1/3] Adding keypad support and example --- .../character_lcd_rgb_i2c.py | 128 +++++++++++++++++- docs/examples.rst | 4 + examples/charlcd_keypad_simpletest.py | 42 ++++++ 3 files changed, 173 insertions(+), 1 deletion(-) create mode 100644 examples/charlcd_keypad_simpletest.py diff --git a/adafruit_character_lcd/character_lcd_rgb_i2c.py b/adafruit_character_lcd/character_lcd_rgb_i2c.py index 7cdd068..f33fa43 100644 --- a/adafruit_character_lcd/character_lcd_rgb_i2c.py +++ b/adafruit_character_lcd/character_lcd_rgb_i2c.py @@ -34,10 +34,13 @@ "* `RGB LCD Shield Kit w/ 16x2 Character Display - Negative Display `_" + "* `RGB LCD Shield Kit w/ 16x2 Character Display - Positive Display `_" + "* `Adafruit RGB Negative 16x2 LCD+Keypad Kit for Raspberry Pi `_" + "* `Adafruit RGB Positive 16x2 LCD+Keypad Kit for Raspberry Pi `_" @@ -50,9 +53,10 @@ """ +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 @@ def __init__(self, i2c, columns, lines): 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 diff --git a/docs/examples.rst b/docs/examples.rst index fc7c555..d30f80d 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -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: diff --git a/examples/charlcd_keypad_simpletest.py b/examples/charlcd_keypad_simpletest.py new file mode 100644 index 0000000..50931d6 --- /dev/null +++ b/examples/charlcd_keypad_simpletest.py @@ -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() From cd3dde487c944f6beba533782ff776de1e230d6a Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Sun, 13 Jan 2019 17:56:43 -0500 Subject: [PATCH 2/3] Revert version line --- adafruit_character_lcd/character_lcd_rgb_i2c.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_character_lcd/character_lcd_rgb_i2c.py b/adafruit_character_lcd/character_lcd_rgb_i2c.py index f33fa43..1377131 100644 --- a/adafruit_character_lcd/character_lcd_rgb_i2c.py +++ b/adafruit_character_lcd/character_lcd_rgb_i2c.py @@ -56,7 +56,7 @@ import digitalio from adafruit_character_lcd.character_lcd import Character_LCD_RGB -__version__ = "3.0.3" +__version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_CharLCD.git" From be794b8c34a567b50166fc80acce52965c3c7687 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Sun, 13 Jan 2019 19:49:25 -0500 Subject: [PATCH 3/3] Update example. --- examples/charlcd_keypad_simpletest.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/examples/charlcd_keypad_simpletest.py b/examples/charlcd_keypad_simpletest.py index 50931d6..73af14e 100644 --- a/examples/charlcd_keypad_simpletest.py +++ b/examples/charlcd_keypad_simpletest.py @@ -21,19 +21,19 @@ print("Left!") lcd.message = "Left!" - if lcd.up_button: + elif lcd.up_button: print("Up!") lcd.message = "Up!" - if lcd.down_button: + elif lcd.down_button: print("Down!") lcd.message = "Down!" - if lcd.right_button: + elif lcd.right_button: print("Right!") lcd.message = "Right!" - if lcd.select_button: + elif lcd.select_button: print("Select!") lcd.message = "Select!"