What to do next?


hi guys!
                hooked 16x2 lcd arduino , hooked tactile button debounced bounce2 library. trying create menu on lcd 4 options , each option(when selected) opens screen text. don't understand when button not pressed. you'll better understand when you'll read code. have made code modular , easy use. please help. here code:
code: [select]

#include <bounce2.h>

#include <liquidcrystal.h>

liquidcrystal lcd(12, 11, 5, 4, 3, 2);

#define button_pin 10
bounce debouncer = bounce();

byte data;
char *menu[] = {
  "1)play","2)instructions","3)about","4)exit" };

int potpin = 0;
int lastval = 0;
int button = 10;

void setup(){
   
  lcd.begin(16, 2);
 
  serial.begin(9600);
  pinmode(potpin, input);
  pinmode(button_pin, input_pullup);
  pinmode(13, output);
 
  debouncer.attach(button_pin);
  debouncer.interval(50);

}

void loop()
{
dataread();
}

int dataread() {
  int val = analogread(potpin);
  val = map(val,0,1023,0,100);
 
  if(val>0 && val<20) {
  updatedisplay(1);
  }
 
  else if(val>20 && val<40) {
  updatedisplay(2);
  }
 
  else if(val>40 && val<60) {
  updatedisplay(3);
  }

  else if(val>60 && val<80) {
  updatedisplay(4);
  }
  else {
   
  }
}

void updatedisplay(int number) {
if(number==1 && number != lastval) {
  lcd.clear();
  lcd.setcursor(0,0);
  lcd.print(menu[0]);
  lcd.setcursor(0,1);
  lcd.print(menu[1]);
  lastval=number;
  displaymarker(1);
}

else if(number==2 && number != lastval) {
  lcd.clear();
  lcd.setcursor(0,0);
  lcd.print(menu[0]);
  lcd.setcursor(0,1);
  lcd.print(menu[1]);
  lastval=number;
  displaymarker(2);
}

else if(number==3 && number != lastval) {
  lcd.clear();
  lcd.setcursor(0,0);
  lcd.print(menu[2]);
  lcd.setcursor(0,1);
  lcd.print(menu[3]);
  lastval=number;
  displaymarker(1);
}

else if(number==4 && number != lastval) {
  lcd.clear();
  lcd.setcursor(0,0);
  lcd.print(menu[2]);
  lcd.setcursor(0,1);
  lcd.print(menu[3]);
  lastval=number;
  displaymarker(2);
}

else {

}
}

void displaymarker(int number) {
if(number==1) {
lcd.setcursor(15,0);
lcd.print("<");
select(1);
}

else if(number==2) {
lcd.setcursor(15,1);
lcd.print("<");
select(2);
}

else if(number==3) {
lcd.setcursor(15,0);
lcd.print("<");
select(3);
}

else if(number==4) {
lcd.setcursor(15,1);
lcd.print("<");
select(4);
}

else {

}
}


int check() {
debouncer.update();
int val = debouncer.read();
if(val==high) {
  serial.println("button debounced!");
  serial.println("not pressed");
return 0;
}

else if(val==low) {
  serial.println("button debounced!");
  serial.println("pressed");
return 1;
}

else {

}
}

void select(int number) {
if(check()==1) {
  if(number==1) {
    lcd.clear();
    lcd.setcursor(0,0);
    lcd.print("let's play!");
  }
  else if(number==2) {
    lcd.clear();
    lcd.setcursor(0,0);
    lcd.print("these the");
    lcd.setcursor(0,1);
    lcd.print("instructions!");
  }
  else if(number==3) {
    lcd.clear();
    lcd.setcursor(0,0);
    lcd.print("made by:");
    lcd.setcursor(0,1);
    lcd.print("owais bin asad");
  }
  else if(number==4) {
    lcd.clear();
    lcd.setcursor(0,0);
    lcd.print("bye bye :d");
  }
}

else {
// here???
}
}
 

the menu works nicely when press button on option, nothing happens! help. think has empty else statement in "select" function @ end.

maybe don't understand your're doing. appears have single switch connected pin 10, should read either high or low depending on state. however, treat potentiometer in code , map value returned , use bunch of if statements decide option selected.  if you're using  pot, attached analog pin (a0-a5) , return value mapped.  what's on pin 10, pot or switch?


Arduino Forum > Using Arduino > Programming Questions > What to do next?


arduino

Comments

Popular posts from this blog

Connecting Raspberry Pi 2 to P10(1R)-V706 LED Dot Matrix - Raspberry Pi Forums

TypeError: <unknown> is not a numpy array - Raspberry Pi Forums

datso and removing imagetitle - Joomla! Forum - community, help and support