Hi,
I want make a LCD Menu with Joystick. I this found a Menu library: Phi_prompt | LiuDr Electronic Solutions LLC Official Blog
I managed to make the menu with analog buttons, but I want to work with the joystick. The joystick has 2 analog outputs ("x" and "y" axis )and 1 digital output (press).
With this library seems easier to use the joystick but not implement it in the menu: phi_interfaces | LiuDr Electronic Solutions LLC Official Blog
menu library with analog buttons:
#define buttons_per_column 5 // Each analog pin has five buttons with resistors.
#define 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}; //These numbers need to increase monotonically. The 342 works better on my setup but you will need to change it back.
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 fhr phi_prompt.
// The following adds all available keypads as inputs for phi_prompt library
multiple_button_input * keypads[]={&analog_keypad, &debug_keypad,0};
PROGMEM prog_char msg_00[]="Developed by:\nDr.Liu 05/23/11\nhttp://liudr.wordpress.com\nThis is just a mock-up of an actual data acquisition system with a 2-level menu.\nIt serves as a template for your actual project. It also shows off various features of the phi_prompt library.\nGo in \"Set Menu Style\" to find out some menu features you could be using in your project.\nPress Confirm to continue";
// Setting up two menus top and sub_1
Phi_interfaces library:
/*
__ ______ ____ ____ _______.___________. __ ______ __ ___
| | / __ \ \ \ / / / | || | / || |/ /
| | | | | | \ \/ / | (----`---| |----`| | | ,----'| ' /
.--. | | | | | | \_ _/ \ \ | | | | | | | <
| `--' | | `--' | | | .----) | | | | | | `----.| . \
\______/ \______/ |__| |_______/ |__| |__| \______||__|\__\
*/
/** \brief class for 2-axis joy sticks
* \details This class provides support to sense a 2-axis joy stick, with either analog output on each axis, or digital output of 8 directional keys.
* These function codes, coupled with the lower level function code of each inheriting child class, completes the translation from sensing physical pins to outputting named buttons with mapping array.
* The function hierarchy is getKey()<---scanKeypad()<---sense_all().
* The sense_all reads digital pins for input.
* The scanKeypad turns these inputs into status changes for keys and provide scan code of the pressed key. It handles status change including debouncing and repeat.
* The getKey translates the key press from scan code (0 to max_key-1) into named keys with the mapping array.
*/
class phi_joysticks:public phi_keypads {
public:
phi_joysticks(char *na, byte *sp, int * dp, int th); ///< Constructor for joystick
byte keyboard_type; ///< This stores the type of the keypad so a caller can use special functions for specific keypads.
int get_x(){return axis_vals[0];} ///< Returns x axis value of the joystick
int get_y(){return axis_vals[1];} ///< Returns y axis value of the joystick
unsigned long button_status_t; ///< This is the time stamp of the sensed button first in the status stored in button_status.
protected:
int axis_vals[2]; ///< This stores the x and y axis values read from analog pin
int threshold; ///< This stores the threshold of matching the joystick with a directional key.
int * values; ///< This pointer points to an integer array with values of analog inputs. The number of values is equal to the number of axis times 3. The array starts with the value of the first axis, when it is pushed up, then the center value of this axis, then the value of this axis when it is pushed down.
byte sense_all(); ///< This senses all input pins.
};
please someone could help me?
thank you!