I am trying to make a menu with the Onebutton library, I have a button that is connected to 2 pins, but I am trying to implement the going back function. If you keep pressing the button, it recognizes it as 2 long presses. What should I do?
Here is my code
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <ESP8266WiFi.h>
#include "OneButton.h"
OneButton Button1(0, true);
OneButton Button2(12, true);
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
#define SCREEN_ADDRESS
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
int buttonpress = 0;
int test = 1;
int testok = 0;
int stop3 = 0;
int stop = 0;
int buttonState = 0;
int button = 13;
int temp = 0;
int lol = 0;
int bro = 1;
const char *ssid = "Dice D1";
const char *password = "10203040";
void setup() {
Serial.begin(9600);
Button1.attachClick(click1);
Button1.attachDuringLongPress(click3);
Button2.attachClick(click10);
Button2.attachDuringLongPress(click13);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
display.clearDisplay();
Serial.print("Setting AP (Access Point)…");
// Remove the password parameter, if you want the AP (Access Point) to be open
WiFi.softAP(ssid, password);
pinMode(button, INPUT);
}
void loop() {
Button1.tick();
delay(10);
Button2.tick();
delay(10);
temp = digitalRead(button);
if(temp == LOW && test == 6 && bro == 1){
lol = 1;
}
if(temp == LOW && test == 6){
lol = 2;
}
if (test == 1){
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(21,28);
display.println("Press Button 1");
display.setCursor(25,37);
display.println(test);
display.display();
delay(0);
display.clearDisplay();
}
if (test == 2){
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(21,28);
display.println("Press Button 2");
display.setCursor(25,37);
display.println(test);
display.display();
delay(0);
display.clearDisplay();
}
if (test == 3){
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(25,28);
display.println("Test finished");
display.setCursor(25,37);
display.println(test);
display.display();
delay(0);
display.clearDisplay();
}
if(test == 4){
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(43,28);
display.println("Wifi On");
display.setCursor(43,37);
display.println(buttonpress);
display.setCursor(43,46);
display.println(lol);
display.display();
delay(0);
display.clearDisplay();
}
if(test == 5 ){
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(43,28);
display.println("Wifi Off");
display.setCursor(43,37);
display.println(buttonpress);
display.setCursor(43,46);
display.println(lol);
display.display();
delay(0);
display.clearDisplay();
}
if(test == 6){
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(43,28);
display.println("Ir Remote");
display.setCursor(43,37);
display.println(buttonpress);
display.setCursor(43,46);
display.println(lol);
display.display();
delay(0);
display.clearDisplay();
}
}
void click1() {
if(test >= 3){
test = test + 1;
}
if(test == 7){
test = 4;
}
if (test == 2 && stop3 == 1){
test = test + 1;
}
}
void click3() {
if(test == 5 && lol == 2){
test = 4;
buttonpress = 1;
lol == 1;
}
if(test == 6 && lol == 1){
test = 5;
bro = 1;
}
}
void click10(){
if(test <= 3 && stop3 == 0){
delay(100);
test = test + 1;
stop3 = 1;
}
}
void click13(){
}