I am here again with a different problem!
Could someone please help me out here? I want to know the proper way of displaying a menu in GLCD using U8GLIB... The error I get is that the screen stays on the same text.. Not going to other menu...
what i want to achieve is that
1.) Display a welcome screen with 2 seconds delay
2.) Display a menu with options and wait until the user enters a value
3.) Go to the relevant option
Here is my code:
#include <Keypad.h>
#include "U8glib.h"
U8GLIB_ST7920_128X64_4X u8g(13, 12, 11);
const byte numRows= 4;
const byte numCols= 4;
char keymap[numRows][numCols]= {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[numRows] = {3,4,5,6};
byte colPins[numCols] = {7,8,9,10};
Keypad mykeypad = Keypad(makeKeymap(keymap), rowPins, colPins, numRows, numCols);
char Password=1*2*3;
void setup()
{
u8g.firstPage ();
do{
welcome ();
} while( u8g.nextPage () );
delay(3000);
}
void welcome(void)
{
u8g.setFont(u8g_font_fub17);
u8g.setPrintPos(16, 25);
u8g.setColorIndex(1);
u8g.drawBox(0,0,128,64);
u8g.setColorIndex(0);
u8g.print("Welcome!");
}
void authentication()
{
char uauth;
u8g.setFont(u8g_font_helvR08);
u8g.setPrintPos(16, 25);
u8g.print("Please enter device");
u8g.setPrintPos(20, 46);
u8g.print("PASSWORD");
uauth = mykeypad.waitForKey();
if (uauth == Password)
{
u8g.firstPage();
do{
MainMenu();
} while( u8g.nextPage() );
}
u8g.setFont(u8g_font_fub17);
u8g.setPrintPos(16, 25);
u8g.print("Invalid Password");
}
void MainMenu(void)
{
int MainOption;
u8g.setFont(u8g_font_helvR08);
u8g.setPrintPos(2, 25);
u8g.print("Choose the options below");
u8g.setFont(u8g_font_fub17);
u8g.setPrintPos(16, 25);
u8g.print(" 1. First Option");
u8g.setPrintPos(16, 25);
u8g.print(" 2. Second Option");
u8g.setPrintPos(16, 25);
u8g.print(" 3. Third Option");
MainOption = mykeypad.getKey();
if(MainOption == 1)
{
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(64, 32);
u8g.print(MainOption);
}
else if(MainOption == 2)
{
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(64, 32);
u8g.print(MainOption);
}
else if(MainOption == 3)
{
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(64, 32);
u8g.print(MainOption);
}
else
{
u8g.setFont(u8g_font_unifont);
u8g.setPrintPos(20, 26);
u8g.print("Invalid choice...");
u8g.setPrintPos(26, 48);
u8g.print("Try again!");
}
}
void loop(void)
{
u8g.firstPage ();
do{
authentication ();
} while( u8g.nextPage () );
}
ERROR I GET
: Screen stays on Welcome! screen and never goes to other functions like authentication(); and MainMenu();
when i press any keys on the keypad, it either loops again or get irregular characters! And never displays a menu etc...
The normal program has to be slightly varied to display the output in U8GLIB
I badly need your help guys! Please help! Thanks!
Also attached the LCD setup for your reference!