Button held or long pressed question

I use a simple arduino code for button on my sketch, single click, combine click. But anyone know if its can use long press or held function?


uint8_t Rp = 2;
uint8_t Bn1p = 3;
uint8_t Bn2p = 4;

boolean R;
boolean Bn1;
boolean Bn2;

void setup(){

pinMode(Rp, INPUT_PULLUP);
pinMode(Bn1p, INPUT_PULLUP);
pinMode(Bn2p, INPUT_PULLUP;)

}

void loop(){

readAll();

if (!R) {
  Serial.print("click");
}

if (!R && !Bn1) {
 Serial.print("R & Bn1 is pressed");
}

}

void readAll() {
  
    Bn1 = digitalRead(Bn1p);
    Bn2 = digitalRead(Bn2p);
    R = digitalRead(Rp);
}

Did you forget to post some of the code?

Which code?

The code that reads the input pins.

Or code that actually compiles, unlike the code you posted

Updated

Still doesn't compile, still has no chance of producing any output

Hello
Your sketch needs a simple button handler that takes care about debouncing, interlook and counting of state changes. You may start the for a single button by using C++ instructions enum, struct, array and so on.

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