DFR0374_LCD_Keypad_Shield_V2.0_Old-DFRobot

DFR0374 LCD Keypad Shield V2.0 for Arduino

Specification

Board Overview

DFR0374.png

Pin Description
AnalogPin0 Buttons (select, up, right, down, left)
DigitalPin4 DB4
DigitalPin5 DB5
DigitalPin6 DB6
DigitalPin7 DB7
DigitalPin8 RS (Data or signal display selection)
DigitalPin9 Enable (start data read/write)
DigitalPin10 Backlight Control

Tutorial

This demo shows how to use 1602 RGB LCD shield.

Requirements

Sample Code

The new Arduino IDE has built-in LiquidCrystal library to drive 1602 screen. If your Arduino IDE does not have this library, please follow the steps below to install it.

About how to install the library?

#include <LiquidCrystal.h>
    //Definitions used on the LCD to pin
    LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

    // Define keys
    int lcd_key = 0;        
    int adc_key_in = 0;        

    #define btnRIGHT 0        
    #define btnUP 1        
    #define btnDOWN 2        
    #define btnLEFT 3        
    #define btnSELECT 4        
    #define btnNONE 5        

    //Read the key value        
    int read_LCD_buttons()        
    {        
    adc_key_in = analogRead(0); // 0 read the ADC from analog values        
    // By setting different threshold, you can read the corresponding to the appropriate buttons        
    if (adc_key_in > 1000) return btnNONE;        
    if (adc_key_in < 50) return btnRIGHT;        
    if (adc_key_in < 250) return btnUP;        
    if (adc_key_in < 450) return btnDOWN;        
    if (adc_key_in < 650) return btnLEFT;        
    if (adc_key_in < 850) return btnSELECT;        
    return btnNONE;        
    }        

    void setup()        
    {        
    lcd.begin(16, 2); // Start        
    lcd.setCursor(0,0);        
    lcd.print("Push the buttons"); //print“Push the buttons”        
    }        

    void loop()        
    {        
    lcd.setCursor(9,1);        
    lcd.print(millis()/1000); // Output wait        


    lcd.setCursor(0,1); //        
    lcd_key = read_LCD_buttons(); // Reading keys        

    switch (lcd_key) // Judge key        
    {        
    case btnRIGHT:        
    {        
    lcd.print("RIGHT ");        
    break;        
    }        
    case btnLEFT:        
    {        
    lcd.print("LEFT ");        
    break;        
    }        
    case btnUP:        
    {        
    lcd.print("UP ");        
    break;        
    }        
    case btnDOWN:        
    {        
    lcd.print("DOWN ");        
    break;        
    }        
    case btnSELECT:        
    {        
    lcd.print("SELECT");        
    break;        
    }        

    {        
    lcd.print("NONE ");        
    break;        
    }        
    }        

More Documents