Well, working functions is a start! reading this thread I noticed the GLCD support in m2tklib.
Please note that I was informed about a bug in M2tklib for GLCD recently. I have released a new version of M2tklib for GLCD today.
Oliver
I'm using LiquidCrystal with a shift register attached LCD. I've hit my first problem though and I suspect it is because of the shift register:
error: cannot convert 'LiquidCrystal_SR*' to 'LiquidCrystal*' for argument '1' to 'void m2_SetLiquidCrystal(LiquidCrystal*, uint8_t, uint8_t)'
Don't read too much into the code, top bit only really needed as I've edited the menubackend code I had.
Question. I have 3 buttons up, down & select , which you have no handler for, I thought no problem I can use SetKey() in my ISR? this is ok I assume?
//DEBUG
#include <MemoryFree.h>
int tempMemCount = 0;
//
/*LCD*/
#include <LCD.h>
#include <LiquidCrystal_SR.h> // ShiftRegister LCD
LiquidCrystal_SR iLCD(10, 11, 12); //Data,Clk,Enable.
//END LCD
//MENU SETUP
#include "M2tk.h"
#include "utility/m2ghlc.h"
//initialize menu
M2_LABEL(hello_world_label, NULL, "Hello World!");
M2tk m2(&hello_world_label, NULL, NULL, m2_gh_lc);
//initialize menuitems
unsigned long menuTimer = millis();
byte timerEnable = 0;
//END MENU
//INTERRUPT BUTTONS
const int pin = 13; // test for interrupt
const int buttonPin = A0; // buttons can be read here
volatile byte buttonAct = 0; // flag, follow button press
volatile int buttonValue = 0; // button pressed analogue value
volatile int buttonPressed = 0; // which button was pressed
volatile byte lastButtonPressed = 0; // prev button pressed
volatile byte state = LOW; // state of led on pin13
volatile byte lastState = HIGH; // unused?
void setup(){
//MENU SETUP
m2_SetLiquidCrystal(&iLCD, 20, 4); // <<<<<<------------- ERROR this line
//configure menu
//END MENU SETUP
Serial.begin(38400);
Serial.println(F("STARTED"));
pinMode(pin, OUTPUT);
attachInterrupt(0, readButtons, RISING);
iLCD.begin(20,4); // initialize the lcd
delay(400); // wait to start lcd writing
iLCD.home (); // go home
iLCD.print(F("Button Interrupt"));
Serial.print(F("freeMemory() reports at startup "));
Serial.println( freeMemory() );
}
void buttonStat(){
Serial.print(buttonPressed);
Serial.print(" ");
Serial.println(lastButtonPressed);
}
void loop(){
if(timerEnable == 1 && millis() - menuTimer >=8000){ //in the middle of something, set menuTimer = 0 to disable and drop timerEnable
Serial.print(F("freeMemory() reports "));
Serial.println( freeMemory() );
Serial.println(F("Timer Clear........."));
/* menu.moveToLevel(1); this resets the uno????*/
// go back to root of menu here
timerEnable = 0;
iLCD.clear(); // go home
iLCD.print(F("Button Interrupt"));
delay(60);
buttonAct = 0;
}
if(buttonAct == 1){ //buttonAct eq 1 when interrupt received
buttonAct = 0;
navMenu();
}
//lastButtonPressed = 0;
delay(100);
tempMemCount++;
if(tempMemCount > 9){ //once a sec will do
Serial.print(F("freeMemory() reports "));
Serial.println( freeMemory() );
tempMemCount = 0;
}
}
void readButtons(){
state = !state;
digitalWrite(pin, state);
/* 511 : none | 614 : up | 768 : down | 1023 : select */
lastButtonPressed = buttonPressed;
buttonValue = analogRead(buttonPin);
if(buttonValue >= 900) {
buttonPressed = 3;
}
else if(buttonValue >= 700){
buttonPressed = 2;
}
else if(buttonValue >= 600){
buttonPressed = 1;
}
buttonAct = 1;
Serial.print(buttonPressed);
Serial.print(" ");
Serial.println(buttonValue);
}
void navMenu(){
//MenuItem currentMenu=menu.getCurrent();
switch (buttonPressed){
case 3: //select
/*
if (menu.getCurrent().getRight() != 0){ //The current item has an element right, it's a sub menu so nav right.
menu.moveRight();
Serial.print(menu.getCurrent().getName());
Serial.println(F("has menu right"));
}
else{ //otherwise, menu has no child and has been pressed. enter the current menu
menu.use();
}
*/
break;
case 2: //down
//menu.moveDown();
break;
case 1: //up
//menu.moveUp();
break;
}
}