How to Detect Short, Long, and Double Clicks with Arduin

I'm new to this and I'm trying to understand.
has Tinypico and has got a Bluetooth started to control the phone.
But I also try to get features like double click single click and long press button

attach the code. up and down arrow works but not the longclick function
does anyone see what I'm doing wrong

[[code]
#include "BleKeyboard.h"
#include "OneButton.h"    //we need the OneButton library

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'},
};

byte rowPins[ROWS] = {23, 19, 18, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {22, 21, 32, 33 }; //connect to the column pinouts of the keypad

OneButton button('1', true);
BleKeyboard bleKeyboard;

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);


void setup() {
  Serial.begin(9600);
  bleKeyboard.begin();
  //button.attachDoubleClick(doubleclick);            // link the function to be called on a doubleclick event.
  //button.attachClick(singleclick);                  // link the function to be called on a singleclick event.
  //button.attachLongPressStop(longclick);            // link the function to be called on a longpress event.
}
void sendMacroCommand(uint8_t key) {
  bleKeyboard.press(KEY_LEFT_CTRL);
  bleKeyboard.press(KEY_LEFT_SHIFT);
  bleKeyboard.press(KEY_LEFT_ALT);
  bleKeyboard.press(key);
}
void longclick() {
  Serial.println("Sending DOWN_ARROW key...");
  bleKeyboard.write(KEY_DOWN_ARROW);
  delay(1000);

}
void loop() {
  char key = keypad.getKey();

  if (bleKeyboard.isConnected() && key) {
    Serial.println(key);
    switch (key) {

      case '2':
        Serial.println("Sending UP_ARROW key...");
        bleKeyboard.write(KEY_UP_ARROW);
        break;
      case '8':
        Serial.println("Sending DOWN_ARROW key...");
        bleKeyboard.write(KEY_DOWN_ARROW);
        break;

    }
  }
}

[/code]

The code, in loop, is not calling the longclick function.

If You read the topics like "How to use this Forum" You would:

  1. Autoformat the code in the IDE. Then copy.
  2. Use code tags according to the advice in 1)

It would come up like this:

#include "BleKeyboard.h"
#include "OneButton.h"    //we need the OneButton library

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'},
};

byte rowPins[ROWS] = {23, 19, 18, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {22, 21, 32, 33 }; //connect to the column pinouts of the keypad

OneButton button('1', true);
BleKeyboard bleKeyboard;

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);


void setup() {
  Serial.begin(9600);
  bleKeyboard.begin();
  //button.attachDoubleClick(doubleclick);            // link the function to be called on a doubleclick event.
  //button.attachClick(singleclick);                  // link the function to be called on a singleclick event.
  //button.attachLongPressStop(longclick);            // link the function to be called on a longpress event.
}
void sendMacroCommand(uint8_t key) {
  bleKeyboard.press(KEY_LEFT_CTRL);
  bleKeyboard.press(KEY_LEFT_SHIFT);
  bleKeyboard.press(KEY_LEFT_ALT);
  bleKeyboard.press(key);
}
void longclick() {
  Serial.println("Sending DOWN_ARROW key...");
  bleKeyboard.write(KEY_DOWN_ARROW);
  delay(1000);

}
void loop() {
  char key = keypad.getKey();

  if (bleKeyboard.isConnected() && key) {
    Serial.println(key);
    switch (key) {

      case '2':
        Serial.println("Sending UP_ARROW key...");
        bleKeyboard.write(KEY_UP_ARROW);
        break;
      case '8':
        Serial.println("Sending DOWN_ARROW key...");
        bleKeyboard.write(KEY_DOWN_ARROW);
        break;

    }
  }
}

Thanks for your advice but do not see the error even though you point it out, you can show it in the code.

John

:confused:

In the IDE, use the Edit tab and search. Search for "longclick". That function is not referred to, not called from any ware meaning it is never executed.

for triple click want want to do

please tell me

for triple click want want to do

please tell me

for triple click ,,want want to do

please tell me

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