Navigation menu using push button

image
void loop(){
count+=1;
double MaxBatteryBar=20;
double battery_bars_pixels,bottom_rect_y = 6;
batteryPercent = count;
// for (batteryPercent;batteryPercent<100;batteryPercent++ )
// {battery_bars_pixels =batteryPercent*MaxBatteryBar/100 ;
display.setCursor(99,5);
display.setTextSize(1);
display.setTextColor(BLACK);

switch (buttonPushCounter) {
case 2:
settings_voltagesetup();
voltage_setup();
break;
case 3:
settings_batteryinfo();
battery_info();
break;
case 4:
settings_poweroff();
poweroff();
break;
case 5:
settings_exit();
exit();

  break;
default:
  attributes();
  charge_status();
  protection();
  break;

}

display.display();
delay(400);

button();
}

// Define functions to call back
void button(){
bool redraw=false;
buttonState = digitalRead(buttonPin);
if (buttonState != lastButtonState) {
if (buttonState == HIGH) {
// if the current state is HIGH then the button
// went from off to on:
redraw=true;
buttonPushCounter++; // add one to counter
if (buttonPushCounter > 5) {
buttonPushCounter = 1;
}
Serial.println(buttonPushCounter);
}
lastButtonState = buttonState;
}
if (redraw == true ) {
display.clearDisplay();
}
}

THIS IS MY CODE TO NAVIGATE THROUGH THE PAGES. MY CONCERN IS THAT HOW SHOULD I NAVIGATE INSIDE THE PAGE.
FOR THE PHOTO UPLOADED I WANT THAT IF I PRESS THE BUTTON TWO TIMES IT SHOULD ENTER THE POWER OFF PAGE AND I SHOULD SELECT ONE OF THE OPTIONS PRESENT THERE THAT IS ON AND OFF.
AND FOR SELECTION I WILL PRESS AND HOLD THE BUTTON FOR 2 TO 3 SECONDS FOR THE SELECTION TO GET REGISTERED.

I AM USING ARDUINO IDE AND CPP LANGUAGE

No need to shout. Or is your keyboard Caps Lock hardwired to on position?

Welcome to the forum, @ompxtel ! You'll find a lot of helpers here, of varying skill and tone, but one of the things we really appreciate is when new members read, and abide by, the guidance here:

So please, format your code appropriately in a new post(after this one, do not edit your first one), and we'll go from there.

1 Like

yes do you have any problem?

Hey, lower case typing! Congratulations, and welcome to Arduino forums!

As @camsysca pointed out, please post your sketch formatted as code for clarity.

@ompxtel You'll "catch more flies with honey than vinegar". Being aggressive, curt, abrupt, or abrasive may feel good, but doesn't attract helpers to your topic.

Your code will not compile. Had you embedded it correctly, we could begin to debug it, but as it is, not so much.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.