menu driven program using 4 buttons in 16X2 lcd
#include<liquidcrystal.h>
liquidcrystal lcd(5,4,3,2,1,0);
const int enter = 10;
const int = 11;
const int down = 12;
const int = 13;
int start =1;
int run =0;
int sel =0;
void screen(unsigned char x);
void setup()
{
pinmode(enter, input);
pinmode(up, input);
pinmode(down, input);
pinmode(back, input);
lcd.begin(16,2);
lcd.clear();
lcd.setcursor(0,0);
lcd.print("loading..");
delay(1000);
lcd.clear();
lcd.setcursor(0,1);
lcd.print("camera project");
delay(1000);
}
void loop()
{
int e = digitalread(enter);
int read_up = digitalread(up);
int read_down = digitalread(down);
int read_back = digitalread(back);
screen('a');
while(start==1)
{
if(e==1)
{
screen('b');
while(e==1)
run=1;
start=0;
sel=0;
}
else
{
run=0;
start=1;
sel=0;
}
}
while(run==1)
{
if(enter==high)
{
screen('d');
while(enter==high);
sel=1;
}
if((up==high)||(down==high))
{
screen('c');
while((up==high)||(down==high));
run=2;
}
if(back==high)
{
screen('b');
while(back==high);
start=1;
run=0;
}
}
}
void screen(unsigned char x)
{
switch(x)
{
case 'a':
lcd.clear();
lcd.setcursor(0,0);
lcd.print("camera project");
delay(1000);
lcd.clear();
lcd.setcursor(0,1);
lcd.print("press < subsel");
break;
case 'b':
lcd.clear();
lcd.setcursor(0,0);
lcd.print("1> motor");
delay(50);
lcd.setcursor(1,0);
lcd.print("press > motor sub");
break;
case 'c':
lcd.clear();
lcd.setcursor(0,0);
lcd.print("2> camera");
lcd.setcursor(1,0);
delay(50);
lcd.print("press > camera sub");
break;
case 'd':
lcd.clear();
lcd.setcursor(0,0);
lcd.print("1> distance ");
delay(50);
lcd.setcursor(1,0);
lcd.print("press > dist i/p");
break;
case 'e':
lcd.clear();
lcd.setcursor(0,0);
lcd.print("1> time ");
delay(50);
lcd.setcursor(1,0);
lcd.print("press > time i/p");
break;
case 'f':
lcd.clear();
lcd.setcursor(0,0);
lcd.print("1> trigger ");
delay(50);
lcd.setcursor(1,0);
lcd.print("press > trig i/p");
break;
}
}
please notify me if there error or please suggest me alternate program .
my ultimate aim create following menu following 4 buttons :
-menu/enter
-up
-down
-back /*back button used go previous menu , not main menu*/
1.menu /* when enter/menu key pressed following has displayed */
a)motor
b)camera
/*up , down buttons used selecting motor or camera option*/
2.motor /*when motor option selected , enter button pressed again following has b displayed */
a)distance
b)time
its menu ->submenu program
liquidcrystal lcd(5,4,3,2,1,0);
const int enter = 10;
const int = 11;
const int down = 12;
const int = 13;
int start =1;
int run =0;
int sel =0;
void screen(unsigned char x);
void setup()
{
pinmode(enter, input);
pinmode(up, input);
pinmode(down, input);
pinmode(back, input);
lcd.begin(16,2);
lcd.clear();
lcd.setcursor(0,0);
lcd.print("loading..");
delay(1000);
lcd.clear();
lcd.setcursor(0,1);
lcd.print("camera project");
delay(1000);
}
void loop()
{
int e = digitalread(enter);
int read_up = digitalread(up);
int read_down = digitalread(down);
int read_back = digitalread(back);
screen('a');
while(start==1)
{
if(e==1)
{
screen('b');
while(e==1)
run=1;
start=0;
sel=0;
}
else
{
run=0;
start=1;
sel=0;
}
}
while(run==1)
{
if(enter==high)
{
screen('d');
while(enter==high);
sel=1;
}
if((up==high)||(down==high))
{
screen('c');
while((up==high)||(down==high));
run=2;
}
if(back==high)
{
screen('b');
while(back==high);
start=1;
run=0;
}
}
}
void screen(unsigned char x)
{
switch(x)
{
case 'a':
lcd.clear();
lcd.setcursor(0,0);
lcd.print("camera project");
delay(1000);
lcd.clear();
lcd.setcursor(0,1);
lcd.print("press < subsel");
break;
case 'b':
lcd.clear();
lcd.setcursor(0,0);
lcd.print("1> motor");
delay(50);
lcd.setcursor(1,0);
lcd.print("press > motor sub");
break;
case 'c':
lcd.clear();
lcd.setcursor(0,0);
lcd.print("2> camera");
lcd.setcursor(1,0);
delay(50);
lcd.print("press > camera sub");
break;
case 'd':
lcd.clear();
lcd.setcursor(0,0);
lcd.print("1> distance ");
delay(50);
lcd.setcursor(1,0);
lcd.print("press > dist i/p");
break;
case 'e':
lcd.clear();
lcd.setcursor(0,0);
lcd.print("1> time ");
delay(50);
lcd.setcursor(1,0);
lcd.print("press > time i/p");
break;
case 'f':
lcd.clear();
lcd.setcursor(0,0);
lcd.print("1> trigger ");
delay(50);
lcd.setcursor(1,0);
lcd.print("press > trig i/p");
break;
}
}
please notify me if there error or please suggest me alternate program .
my ultimate aim create following menu following 4 buttons :
-menu/enter
-up
-down
-back /*back button used go previous menu , not main menu*/
1.menu /* when enter/menu key pressed following has displayed */
a)motor
b)camera
/*up , down buttons used selecting motor or camera option*/
2.motor /*when motor option selected , enter button pressed again following has b displayed */
a)distance
b)time
its menu ->submenu program
code: [select]
const int enter = 10;
const int = 11;
const int down = 12;
const int = 13;
int e = digitalread(enter);
int read_up = digitalread(up);
int read_down = digitalread(down);
int read_back = digitalread(back);
while(e==1)
run=1;
this going problem if "enter" input ever high (1). sit in loop forever, waiting 'e' change.
what meant write is:
code: [select]
while(digitalread(enter))
run=1;
you have made similar mistakes elsewhere in sketch. see state of pin have digitalread().
fix of errors , try again.
Arduino Forum > Using Arduino > Programming Questions > menu driven program using 4 buttons in 16X2 lcd
arduino
Comments
Post a Comment