Hello,
Im trying to make a Menu that has 4 pages using an i2c 16x2 display. Only one button would be used to naviagate through the menues...
Could anyone provide me with what software and a diagram of how am I supposed to wire up the button to the arduino...?
If not where am I supposed to look for help?
Thanks?
spycatcher2k:
Sure - £150 AND I'LL DO IT
or open, read & understand the examples supplied on this web site. You should have a working example in a couple of hours. Were here to help, not do your work for you 
Ok I got an open-source code up and running. How do I wire up the button(s)?
// ===================================================================
// Example for LCD Keypad Shield from http://www.nuelectronics.com/
// -------------------------------------------------------------------
// * Modified to use a patched LiquidCrystal library
// * Alternative routine to detect keys
// ===================================================================
#include <stdio.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
// ===================================================================
// hardware settings
#define rightKey 0
#define upKey 1
#define downKey 2
#define leftKey 3
#define selectKey 4
#define NUM_KEYS 5
// ===================================================================
// Program parameters
#define minOpt1 5
#define maxOpt1 999
int valueOpt1 = 15;
#define minOpt2 1
#define maxOpt2 99
int valueOpt2 = 10;
#define programMode1 0
#define programMode2 1
#define programMode3 2
int programMode = programMode1;
boolean inMainProgram = false;
int programmSequence = 0;
#define sequenceModeSelect 0
#define sequenceModeOption 1
#define sequenceModeProgram 2
// first menu line - description of menu level
char sequenceHeader[3][17] = {"Mode select ", "Option select ", "Program start "};
// second menu line - mode select
char sequenceModes[3][17] = {" Mode 1 >", "< Mode 2 >", "< Mode 3 "};
// second menu line - options settings
char sequenceOptions[3][17] = {"Option 1: ", "Option 2: ", "no options "};
void setup()
{
// initial lcd display while initialize and pc detection
lcd.begin();
lcd.clear();
lcd.print("Freeduino 0.0.1");
programmSequence = sequenceModeSelect;
inMainProgram = false;
delay(2000);
updateScreen();
}
// ===================================================================
// main loop with new key detection
int keyEvent = -1;
int lastEvent = -1;
int countEvent = 0;
//Key message
char msgs[5][3] = {
"> ",
"^ ",
"v ",
"< ",
"* " };
void updateScreen()
{
lcd.clear();
lcd.print(sequenceHeader[programmSequence]);
lcd.setCursor(0,1);
switch(programmSequence)
{
case sequenceModeSelect:
menuModeSelect( keyEvent );
break;
case sequenceModeOption:
menuOptionSelect( keyEvent );
break;
case sequenceModeProgram:
break;
}
}
void loop()
{
int keyEvent = detectKey();
if (keyEvent >= 0)
{
switch (keyEvent)
{
case upKey:
if (!inMainProgram)
{
if (programmSequence > sequenceModeSelect)
programmSequence--;
updateScreen();
}
break;
case downKey:
if (!inMainProgram)
{
if (programmSequence < sequenceModeProgram)
programmSequence++;
updateScreen();
}
break;
case rightKey:
case leftKey:
if (!inMainProgram)
{
switch (programmSequence)
{
case sequenceModeSelect:
menuModeSelect( keyEvent );
break;
case sequenceModeOption:
menuOptionSelect( keyEvent );
break;
case sequenceModeProgram:
break;
}
}
break;
case selectKey:
lcd.setCursor(0, 1);
if (lastEvent != keyEvent)
{
lastEvent = keyEvent;
countEvent=0;
}
else
countEvent++;
lcd.print(msgs[keyEvent]);
lcd.print(countEvent);
break;
}
}
}
// ===================================================================
// Menu tools
void menuModeSelect( int keyEvent )
{
switch (keyEvent)
{
case rightKey:
if (programMode < programMode3)
programMode++;
break;
case leftKey:
if (programMode > programMode1)
programMode--;
break;
}
lcd.setCursor(0,1);
lcd.print( sequenceModes[programMode] );
}
void menuOptionSelect( int keyEvent )
{
char cbuf[4] = " ";
lcd.setCursor(0,1);
lcd.print(sequenceOptions[programMode]);
switch (keyEvent)
{
case rightKey:
switch (programMode)
{
case programMode1:
if (valueOpt1 < maxOpt1)
valueOpt1++;
break;
case programMode2:
if (valueOpt2 < maxOpt2)
valueOpt2++;
break;
}
break;
case leftKey:
switch (programMode)
{
case programMode1:
if (valueOpt1 > minOpt1)
valueOpt1--;
break;
case programMode2:
if (valueOpt2 > minOpt2)
valueOpt2--;
break;
}
break;
}
switch(programMode)
{
case programMode1:
if (valueOpt1 > minOpt1)
lcd.print("<");
else
lcd.print(" ");
sprintf(cbuf,"%3d",valueOpt1);
lcd.print(cbuf);
if (valueOpt1 < maxOpt1)
lcd.print(">");
else
lcd.print(" ");
break;
case programMode2:
if (valueOpt2 > minOpt2)
lcd.print("<");
else
lcd.print(" ");
sprintf(cbuf,"%2d",valueOpt2);
lcd.print(cbuf);
if (valueOpt2 < maxOpt2)
lcd.print(">");
else
lcd.print(" ");
break;
}
}
// ===================================================================
// Lcd tools
void clearLine(int line)
{
lcd.setCursor(0,line);
lcd.print(" ");
lcd.setCursor(0,line);
}
// ===================================================================
// Define a custom char in lcd
int defineCharacter(int ascii, int data) {
int baseAddress = (ascii * 8) + 64;
// baseAddress = 64 | (ascii << 3);
lcd.command(baseAddress);
for (int i = 0; i < 8; i++)
lcd.write(data);
lcd.command(128);
return ascii;
}
// ===================================================================
// Convert ADC value to key number*
int adc_key_val[NUM_KEYS] ={ 30, 150, 360, 535, 760 };
int get_key(unsigned int input)
{
* int k;
for (k = 0; k < NUM_KEYS; k++)
{
if (input < adc_key_val[k])
return k;
}
if (k >= NUM_KEYS)
k = -1; // No valid key pressed*
* return k;
}
// ===================================================================
// new key detection routine, without delays!
int lastKeyEvent = 0;
int curKeyEvent = 0;
int keyToReturn = 0;
boolean keyToProcess = false;
int adc_key_in = 0;
int detectKey()
{
keyToReturn = -1;
adc_key_in = analogRead(0); // read the value from the sensor
curKeyEvent = get_key(adc_key_in); // convert into key press*
* if (curKeyEvent != lastKeyEvent)
{
if (!keyToProcess)
{
lastKeyEvent = curKeyEvent;
keyToProcess = true;
}
else*
* {
keyToReturn = lastKeyEvent;
lastKeyEvent = -1;
keyToProcess = false;
}
}
return keyToReturn;
}
// ===================================================================[/sup]*
Ok. I figured out 95% of the stuff. Im unsure how would I program the button that after being on the last page that if i press a button it returns to the first page.
Code
void process_display(){
switch (right) {
case 0:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Volts");
lcd.setCursor(0,1);
lcd.print("Amps");
break;
case 1:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Analog 1");
lcd.setCursor(0,1);
lcd.print("Value");
break;
case 2:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Analog 2");
lcd.setCursor(0,1);
lcd.print("Value");
break;
case 3:
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Analog 3");
lcd.setCursor(0,1);
lcd.print("Value");
break;
}
}
You need to use Code Tags and post all of your code. See How to use this forum
So I am only guessing that maybe you need something like this, but you didn't post the section it needs to go in.
if (right >3)
{
right = 0;
}