I'm trying to build a menu with an Arduino Uno and the (great!) Adafruit RGB backlight LCD 2x16. To do so, I used the corresponding library Adafruit_RGBLCDShield. Unfortunately the detection of pressed buttons is not configured on falling edge and one pressure makes several items scrolling instead of only one ! Could you help me finding an issue ?
Here is my code :
Code: Select all
// include the library code:
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
// These #defines make it easy to set the backlight color
#define RED 0x1
#define GREEN 0x2
#define BLUE 0x4
#define WHITE 0x7 //Other colors : YELLOW 0x3|TEAL 0x6|VIOLET 0x5
typedef struct node {
char *menuString; // menu title
struct node *parent; // the 'parent' element
struct node *prevSibling; // the 'previous sibling' element
struct node *nextSibling; // the 'next sibling' element
struct node *firstChild; // the 'first child' element
} menuItem;
menuItem *menuPtr; // define the pointer through menu selected
//Build nodes
menuItem configuration = {"CONFIGURATION",0,0,0,0};
menuItem essai = {"ESSAI",0,&configuration,0,0};
menuItem resultats = {"RESULTATS",0,&essai,0,0};
menuItem tension_seuil = {"Tension seuil",&configuration,0,0,0};
void setup() {
Serial.begin(9600);// Debugging output
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
lcd.setBacklight(WHITE); //Set the backlight to white
// Build links between nodes
configuration.firstChild = &tension_seuil; // tell configuration menu how to find its first child
configuration.nextSibling = &essai; //tell configuration menu how to find its sibling
essai.nextSibling = &resultats; //tell essai menu how to find its sibling
menuPtr = &configuration; //Initialize menu pointer
lcd.print(menuPtr->menuString); //Print it
}
uint8_t i=0;
void loop() {
lcd.setCursor(0, 0); // set the cursor to column 0, line 1 (note: line 1 is the second row, since counting begins with 0)
uint8_t buttons = lcd.readButtons();
if (buttons) {
lcd.clear();
if (buttons & BUTTON_UP) {
if (menuPtr->prevSibling!=0){
menuPtr = menuPtr->prevSibling;
}
lcd.print(menuPtr->menuString);
}
if (buttons & BUTTON_DOWN) {
if (menuPtr->nextSibling!=0){
menuPtr = menuPtr->nextSibling;
}
lcd.print(menuPtr->menuString);
}
if (buttons & BUTTON_LEFT) {
if (menuPtr->parent!=0){
menuPtr = menuPtr->parent;
}
lcd.print(menuPtr->menuString);
}
if (buttons & BUTTON_RIGHT) {
if (menuPtr->firstChild!=0){
menuPtr = menuPtr->firstChild;
}
lcd.print(menuPtr->menuString);
}
if (buttons & BUTTON_SELECT) {
lcd.print(menuPtr->menuString);
}
}
}
Matthieu