示例#1
0
def initLCD():
    # Modify this if you have a different sized character LCD
    lcd_columns = 16
    lcd_rows = 2

    # Raspberry Pi Pin Config:
    lcd_rs = digitalio.DigitalInOut(board.D26)  # pin 4
    lcd_en = digitalio.DigitalInOut(board.D19)  # pin 6
    lcd_d7 = digitalio.DigitalInOut(board.D27)  # pin 14
    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)



    # Initialise the LCD class
    lcd = characterlcd.Character_LCD_RGB(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7, lcd_columns,
                                     lcd_rows, red, green, blue, lcd_backlight)

    return(lcd)
示例#2
0
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)

# Initialise the LCD class
lcd = characterlcd.Character_LCD_RGB(
    lcd_rs,
    lcd_en,
    lcd_d4,
    lcd_d5,
    lcd_d6,
    lcd_d7,
    lcd_columns,
    lcd_rows,
    red,
    green,
    blue,
    lcd_backlight,
)

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

while True:
    lcd.clear()
    lcd.message = "CircuitPython\nRGB Test: RED"
    lcd.color = RED
示例#3
0
    def __init__(self,
                 rows: int,
                 columns: int,
                 rs_pin: DigitalInOut,
                 en_pin: DigitalInOut,
                 d7_pin: DigitalInOut,
                 d6_pin: DigitalInOut,
                 d5_pin: DigitalInOut,
                 d4_pin: DigitalInOut,
                 colour_lcd: bool,
                 i2c_enabled: bool,
                 red_pin: PWMOut = None,
                 green_pin: PWMOut = None,
                 blue_pin: PWMOut = None,
                 backlight_pin: DigitalInOut = None,
                 button_controller: ButtonController = None):
        """
        Create a Display object to simplify LCD operations.

        The pins need to be specified as following:
        digitalio.DigitalInOut( board.<PIN> )

        For colours:
        pulseio.PWMOut( board.<PIN> )

        If it's a colour LCD, the pins for RED, GREEN and BLUE must be specified. backlight_pin can remain None.
        If it's a mono LCD, the backlight pin has to be specified.

        :param rows: Amount of rows on the LCD.
        :param columns: Amount of columns on the LCD.
        :param rs_pin: Location where the RS pin is connected on the board.
        :param en_pin: Location where the EN pin is connected on the board.
        :param d7_pin: Location where the D7 pin is connected on the board.
        :param d6_pin: Location where the D6 pin is connected on the board.
        :param d5_pin: Location where the D5 pin is connected on the board.
        :param d4_pin: Location where the D4 pin is connected on the board.

        :param colour_lcd: Whether it's a colour display or not.
        :param i2c_enabled: Whether the screen has buttons or not.

        :param red_pin: Location where the RED pin is connected on the board.
        :param blue_pin: Location where the BLUE pin is connected on the board.
        :param green_pin: Location where the GREEN pin is connected on the board.

        :param backlight_pin: Location where the backlight pin is connected on the board.

        :param button_controller: A Button Controller class.
        """

        # Set a global variable for checking if it's a colour LCD or not.
        # Then set the colour tuple for a blue screen.
        self.is_colour_lcd = colour_lcd
        self.is_i2c = i2c_enabled
        self.colour = None
        self.set_colour(0, 0, 100)

        # Set a global variable with the dimensions
        self.dimensions = (columns, rows)

        if self.is_i2c:
            if self.is_colour_lcd:
                self.lcd = i2crgb.Character_LCD_RGB_I2C(
                    button_controller.i2c, columns, rows)
            else:
                self.lcd = i2cmono.Character_LCD_I2C(button_controller.i2c,
                                                     columns, rows)
        else:
            # Initialise the LCD screen (type depending on the type of screen).
            if self.is_colour_lcd:
                self.lcd = charlcd.Character_LCD_RGB(rs_pin, en_pin, d4_pin,
                                                     d5_pin, d6_pin, d7_pin,
                                                     columns, rows, red_pin,
                                                     blue_pin, green_pin)
            else:
                self.lcd = charlcd.Character_LCD_Mono(rs_pin, en_pin, d4_pin,
                                                      d5_pin, d6_pin, d7_pin,
                                                      columns, rows,
                                                      backlight_pin)