Hello Community,
i modifide a little Menu for my SainSmart Graphic Shield, but when i print out the "digital pin"-Site and want to the next site, i'll come to the Menu! Why?
Hope for help
Adrian
Code:
#include "LCD4884.h"
#include "SainSmart.h"
#include "SainSmart_chinese.h"
#include <stdio.h>
#include <stdlib.h>
//keypad debounce parameter
#define DEBOUNCE_MAX 15
#define DEBOUNCE_ON 10
#define DEBOUNCE_OFF 3
#define NUM_KEYS 5
#define NUM_MENU_ITEM 4
// joystick number
#define LEFT_KEY 0
#define CENTER_KEY 1
#define DOWN_KEY 2
#define RIGHT_KEY 3
#define UP_KEY 4
// menu starting points
#define MENU_X 10 // 0-83
#define MENU_Y 1 // 0-5
int adc_key_val[5] ={
50, 200, 400, 600, 800 };
// debounce counters
byte button_count[NUM_KEYS];
// button status - pressed/released
byte button_status[NUM_KEYS];
// button on flags for user program
byte button_flag[NUM_KEYS];
boolean checkBacklight;
// menu definition
char menu_items[NUM_MENU_ITEM][12]={
"INPUT PINS",
"OUTPUT PINS",
"BACKLIGHT",
"ABOUT"
};
void (*menu_funcs[NUM_MENU_ITEM])(void) = {
input_pins,
output_pins,
backlight,
about
};
char current_menu_item;
void loop()
{
byte i;
for(i=0; i<NUM_KEYS; i++){
if(button_flag[i] !=0){
button_flag[i]=0; // reset button flag
switch(i){
case UP_KEY:
// current item to normal display
lcd.LCD_write_string(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_NORMAL );
current_menu_item -=1;
if(current_menu_item <0) current_menu_item = NUM_MENU_ITEM -1;
// next item to highlight display
lcd.LCD_write_string(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_HIGHLIGHT );
break;
case DOWN_KEY:
// current item to normal display
lcd.LCD_write_string(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_NORMAL );
current_menu_item +=1;
if(current_menu_item >(NUM_MENU_ITEM-1)) current_menu_item = 0;
// next item to highlight display
lcd.LCD_write_string(MENU_X, MENU_Y + current_menu_item, menu_items[current_menu_item], MENU_HIGHLIGHT );
break;
case LEFT_KEY:
init_MENU();
current_menu_item = 0;
break;
case CENTER_KEY:
lcd.LCD_clear();
(*menu_funcs[current_menu_item])();
lcd.LCD_clear();
init_MENU();
current_menu_item = 0;
break;
}
}
}
}
void input_pins()
{
char buf[10];
byte key = 0xFF;
byte i;
lcd.LCD_write_string(3, 2, "All Pins", MENU_NORMAL);
lcd.LCD_write_string(3, 3, "are INPUT", MENU_NORMAL);
delay(3000);
lcd.LCD_clear();
//DIGITAL PINS
while (key != CENTER_KEY) {
lcd.LCD_write_string(3, 1, "dp8:", MENU_NORMAL);
lcd.LCD_write_string(35, 1, itoa(digitalRead(8), buf, 10), MENU_NORMAL);
lcd.LCD_write_string(3, 2, "dp9:", MENU_NORMAL);
lcd.LCD_write_string(35, 2, itoa(digitalRead(9), buf, 10), MENU_NORMAL);
lcd.LCD_write_string(3, 3, "dp10:", MENU_NORMAL);
lcd.LCD_write_string(35, 3, itoa(digitalRead(10), buf, 10), MENU_NORMAL);
lcd.LCD_write_string(38, 5, "Weiter", MENU_HIGHLIGHT);
for(i=0; i<NUM_KEYS; i++){
if(button_flag[i] !=0){
button_flag[i]=0; // reset button flag
if(i== CENTER_KEY) key=CENTER_KEY;
}
}
}
delay(1000);
lcd.LCD_clear();
//ANALOG PINS
while (key != CENTER_KEY) {
lcd.LCD_write_string( 3, 1, "A1:", MENU_NORMAL);
lcd.LCD_write_string( 40, 1, itoa(analogRead(A1), buf, 10), MENU_NORMAL);
lcd.LCD_write_string( 3, 2, "A2:", MENU_NORMAL);
lcd.LCD_write_string( 40, 2, itoa(analogRead(A2), buf, 10), MENU_NORMAL);
lcd.LCD_write_string( 3, 3, "A3:", MENU_NORMAL);
lcd.LCD_write_string( 40, 3, itoa(analogRead(A3), buf, 10), MENU_NORMAL);
lcd.LCD_write_string( 3, 4, "Stick: ", MENU_NORMAL);
lcd.LCD_write_string( 40, 4, itoa(analogRead(A0), buf, 10), MENU_NORMAL);
lcd.LCD_write_string(45, 5, "Menu", MENU_HIGHLIGHT );
for(i=0; i<NUM_KEYS; i++){
if(button_flag[i] !=0){
button_flag[i]=0; // reset button flag
if(i== CENTER_KEY) key=CENTER_KEY;
}
}
}
}
You can download the code from here, but you'll need some external libraries: https://dl.dropbox.com/u/42107981/LCD4884_sainsmart.ino