Hi there
I've a problem with the OneButton library and a very simple sketch.
I connected an led from D7 to a 220 ohms resistor to ground and
I connected an pushbutton from A0 to Ground.
My sketch contains only two functions, menu0 and menu1. On
powerup menu0 is called by default.
If I long-press the button I enter menu1 and the led lights up.
The goal is if I long-press the button again while I am in menu1
the sketch should go back into menu0 and the led goes off.
The problem is it does not go back to menu0 OR it does but instantly returns back to
menu1 because the led flickers shortly. So my guess is that as I long-press the button it recognizes it as multiple long-press...
Thats my sketch:
#include "OneButton.h"
unsigned short cur_menu = 0;
unsigned short ledPin = 7;
OneButton button(A0, true);
void setup() {
button.attachClick(click);
button.attachDuringLongPress(lp);
pinMode(ledPin, OUTPUT);
menu0();
}
void loop() {
button.tick();
delay(20);
}
void click() {
}
void lp() {
if(cur_menu == 1)
menu0();
if(cur_menu == 0)
menu1();
}
void menu0() {
cur_menu = 0;
digitalWrite(ledPin, LOW);
}
void menu1() {
cur_menu = 1;
digitalWrite(ledPin, HIGH);
}
Any ideas how to solve that?