You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. I am wiring a GUI for a digital watch/wearable. I am using the Button2 library and the isPressed() method to determine when selections are made. Perhaps my understanding of the the method is incorrect. I assume if I have a button e.g. buttonBack and I use if (buttonBack.isPressed()){ insert code }
this will only be executed if the button is currently being pressed. What I am finding is that this seems to stay "latched" on many occasions and results in buttonBack.isPressed() evaluating to a value of 1 even if the button is not being pressed. I have played around with the debounce times and do not believe it is noise. I will include the loop portion of my code and delete some of the lines that are not relevant so you have an idea of what I am doing.
`void loop() {
}
if (buttonBack.isPressed()){
mode=1;
oldMode=0;
break;
}
if (buttonEnter.isPressed()){
mode=currentMenuSelection+2;
break;
}
oldMode=mode;
loopbuttons();
break;
case 1:
if (buttonUp.isPressed()|buttonDown.isPressed()){
mode=0;
oldMode=1;
break;
}
printScreen();
loopbuttons();
break;
case 2: //settings
if (oldMode!=mode){
}
if (buttonBack.isPressed()){
mode=0;
oldMode=1;
break;
}
oldMode=mode;
loopbuttons();
break;
case 3: //Alarm
if (oldMode!=mode){
}
if (buttonBack.isPressed()){
mode=0;
oldMode=1;
break;
}
oldMode=mode;
loopbuttons();
break;
case 4: //Stopwatch
if (oldMode!=mode){
}
if (buttonBack.isPressed()){
mode=0;
oldMode=1;
break;
}
oldMode=mode;
loopbuttons();
break;
case 5: //Flashlight
if (oldMode!=mode){
}
if (buttonBack.isPressed()){
mode=0;
oldMode=1;
break;
}
oldMode=mode;
loopbuttons();
break;
}
}
one thing of interest is that the code may encounter the ' if (buttonBack.isPressed()){' multiple times prior to seeing loopbuttons(); which is simply the following:
'void loopbuttons(){
buttonUp.loop();buttonEnter.loop();buttonDown.loop();buttonBack.loop();
if (alarmFlag==1){
alarmRing();
}
if ((millis()-lastButtonPressedTime)>(buttonInactiveSleepTime*1000)){
deepSleep(dummyButton);
}
}'
At first I thought this was the issue, but even If I add loopbuttons(); at various locations, it still doesn't seem to work. I can always use a button clickHandler, but that is a bunch more code than simply using isPressed();
The text was updated successfully, but these errors were encountered:
Hey, isPressed() is only true during the fact. Without spending too much time reading your code wasPressed() might be the function that you are looking for.
Hi. I am wiring a GUI for a digital watch/wearable. I am using the Button2 library and the isPressed() method to determine when selections are made. Perhaps my understanding of the the method is incorrect. I assume if I have a button e.g. buttonBack and I use
if (buttonBack.isPressed()){ insert code }
this will only be executed if the button is currently being pressed. What I am finding is that this seems to stay "latched" on many occasions and results in buttonBack.isPressed() evaluating to a value of 1 even if the button is not being pressed. I have played around with the debounce times and do not believe it is noise. I will include the loop portion of my code and delete some of the lines that are not relevant so you have an idea of what I am doing.
`void loop() {
switch (mode){
case 0 :
if (oldMode!=mode){
int numMenuItems = 4;
buttonUp.setClickHandler([scrollDirection, numMenuItems, bitmaps1=bitmaps1, menuLabels1=menuLabels1](Button2 &btn){
scrollMenu(RIGHT, numMenuItems, bitmaps, menuLabels,btn);
});
buttonUp.setLongClickDetectedHandler([scrollDirection, numMenuItems, bitmaps1=bitmaps1, menuLabels1=menuLabels1](Button2 &btn){
scrollMenu(RIGHT, numMenuItems, bitmaps, menuLabels,btn);
});
buttonUp.setLongClickDetectedRetriggerable(1);
buttonDown.setClickHandler([scrollDirection, numMenuItems, bitmaps1=bitmaps1, menuLabels1=menuLabels1](Button2 &btn){
scrollMenu(LEFT, numMenuItems, bitmaps, menuLabels,btn);
});
buttonDown.setLongClickDetectedHandler([scrollDirection, numMenuItems, bitmaps1=bitmaps1, menuLabels1=menuLabels1](Button2 &btn){
scrollMenu(LEFT, numMenuItems, bitmaps, menuLabels,btn);
});
buttonDown.setLongClickDetectedRetriggerable(1);
currentMenuSelection=0;
}
if (buttonBack.isPressed()){
mode=1;
oldMode=0;
break;
}
if (buttonEnter.isPressed()){
mode=currentMenuSelection+2;
break;
}
oldMode=mode;
loopbuttons();
break;
case 1:
if (buttonUp.isPressed()|buttonDown.isPressed()){
mode=0;
oldMode=1;
break;
}
printScreen();
loopbuttons();
break;
case 2: //settings
if (oldMode!=mode){
if (buttonBack.isPressed()){
mode=0;
oldMode=1;
break;
}
oldMode=mode;
loopbuttons();
break;
case 3: //Alarm
if (oldMode!=mode){
}
if (buttonBack.isPressed()){
mode=0;
oldMode=1;
break;
}
oldMode=mode;
loopbuttons();
break;
case 4: //Stopwatch
if (oldMode!=mode){
}
if (buttonBack.isPressed()){
mode=0;
oldMode=1;
break;
}
oldMode=mode;
loopbuttons();
break;
case 5: //Flashlight
if (oldMode!=mode){
}
if (buttonBack.isPressed()){
mode=0;
oldMode=1;
break;
}
oldMode=mode;
loopbuttons();
break;
}
}
one thing of interest is that the code may encounter the ' if (buttonBack.isPressed()){' multiple times prior to seeing loopbuttons(); which is simply the following:
'void loopbuttons(){
buttonUp.loop();buttonEnter.loop();buttonDown.loop();buttonBack.loop();
if (alarmFlag==1){
alarmRing();
}
if ((millis()-lastButtonPressedTime)>(buttonInactiveSleepTime*1000)){
deepSleep(dummyButton);
}
}'
At first I thought this was the issue, but even If I add loopbuttons(); at various locations, it still doesn't seem to work. I can always use a button clickHandler, but that is a bunch more code than simply using isPressed();
The text was updated successfully, but these errors were encountered: