D
D
Denis2022-02-05 14:11:57
Arduino
Denis, 2022-02-05 14:11:57

How to do isRelease correctly?

I work with the Gaver Button library. A very good library from my point of view, but there was a problem with which I can not get along. Here is an outline of the problem:

#define BTN_PIN 2 
#include "GyverButton.h"
GButton butt1(BTN_PIN);

boolean flag = true;

void setup() {
  Serial.begin(9600);
}

void loop() {
  butt1.tick();
  
  if (butt1.isStep()) { // Удержание
    flag = true;
  }
  if (butt1.isStep(1)) { // Клик + Удержание
    if(flag) flag = false;
  }
  if (butt1.isRelease()){ // Отпускание кнопки
    flag = false;
  }
}


I don't know if I was able to give an example of the problem. Just in case, I will write step by step.
To make a click + hold , you need to: press the button, release , and hold the button. Here, when released, the isRelease flag changes and everything goes through the ass. How can I make it so that isRelease does not fire on click + hold ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
kalapanga, 2022-02-05
@kalapanga

It is better to ask about the libraries of this friend on his own forum:
https://community.alexgyver.ru/

B
Borys Latysh, 2022-02-06
@nava2002

void loop() {
butt1.tick();
if (butt1.isStep()) { // Hold
flag = true;
}
if (butt1.isStep(1)) { // Click - first
if (butt1.isStep()) { // Hold - then
flag = true;
if (butt1.isRelease()){ // Release the button
flag = false;
}
}
if(flag) flag = false;
}
}
Well, something like this, you need to try to invest Ifa what she will do, but the idea is this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question