dweston:
Thanks liudr
The mapping that appears to work correctly on the DFR-007 16x2 LCD Keypad is:
char analog_mapping[]={'R','U','D','L','B'};
A successfully implemented example is as follows:
#include <LiquidCrystal.h>
#include <Wire.h>
#include <stdio.h>
#include <avr/pgmspace.h>
#include <phi_interfaces.h>
#include <phi_prompt.h>
//DFRobot LCD shield pin setting
#define LCD_RS 8
#define LCD_EN 9
#define LCD_D4 4
#define LCD_D5 5
#define LCD_D6 6
#define LCD_D7 7
//DFRobot LCD shield row & column assignments
#define lcd_rows 2
#define lcd_columns 16
#define analog_buttons_per_column 5 // Each analog pin has five buttons with resistors.
#define analog_buttons_per_row 1 // There are two analog pins in use.
#define name_length 8 // This is the max length of names.
char analog_mapping[]={'R','U','D','L','B'}; // This is an analog keypad.
byte analog_pins[]={0}; // The pin numbers are analog pin numbers.
int values[]={0, 143, 328, 503, 741}; // Measured switch threshold values
phi_analog_keypads analog_keypad(analog_mapping, analog_pins, values, analog_buttons_per_row, analog_buttons_per_column);
// This serial keypad is for debugging.
phi_serial_keypads debug_keypad(&Serial,9600);
// The following sets up function keys for phi_prompt library
char up_keys[]={"U"}; ///< All keys that act as the up key are listed here.
char down_keys[]={"D"}; ///< All keys that act as the down key are listed here.
char left_keys[]={"L"}; ///< All keys that act as the left key are listed here.
char right_keys[]={"R"}; ///< All keys that act as the right key are listed here.
char enter_keys[]={"B"}; ///< All keys that act as the enter key are listed here.
char escape_keys[]={"A"}; ///< All keys that act as the escape key are listed here.
char * function_keys[]={up_keys,down_keys,left_keys,right_keys,enter_keys,escape_keys}; ///< All function key names are gathered here for phi_prompt.
// The following adds all available keypads as inputs for phi_prompt library
multiple_button_input * keypads[]={&analog_keypad, &debug_keypad,0};
int backLight = 10; // LCD Panel Backlight LED connected to digital pin 10
int lightLevel = 255; // Initialise light full on
// The following sets up LCD and other objects
LiquidCrystal lcd(LCD_RS,LCD_EN,LCD_D4,LCD_D5,LCD_D6,LCD_D7); // Create the lcd object
void setup()
{
lcd.begin(lcd_columns, lcd_rows);
init_phi_prompt(&lcd,keypads,function_keys, lcd_columns, lcd_rows, '~'); // Supply the liquid crystal object, input keypads, and function key names. Also supply the column and row of the lcd, and indicator as '>'. You can also use '\x7e', which is a right arrow.
Serial.begin(9600); // Serial is used as a debug keypad. This can be deleted after debug.
}
void loop()
{
phi_prompt_struct myTextInput; // This struct stores information for library functions.
char file_name[]="TEST0000.TXT"; // This buffer stores the content of the text panel.
myTextInput.ptr.msg=file_name; // Assign the text buffer address
myTextInput.low.c='A'; // Text panel valid input starts with character 'A'.
myTextInput.high.c='Z'; // Text panel valid input ends with character 'Z'.
myTextInput.width=12; // Length of the input panel is 12 characters.
myTextInput.col=2; // Display input panel at column 2
myTextInput.row=1; // Display input panel at row 1
myTextInput.option=1; // Option 1 includes 0-9 as valid characters. Option 0, default 'A-Z' only.
lcd.clear(); // Clear the lcd
lcd.print("File name:"); // Prompt user for input
input_panel(&myTextInput); // User input is stored in file_name. Notice the “&”.
/*
The user text input is stored in file_name after the function returns.
*/
Serial.println(file_name);
}
I'm glad it worked. I'm releasing a new version of the library so there will be some simple_menu functions besides what it already has. You may simply send the function a string spelling out the entire menu and the return is which choice the user made. Gong to mighty easy to do menus.