Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Odd behavior with a 5 buttons keypad (no press value different from 0) #5

Open
s-celles opened this issue Feb 6, 2022 · 4 comments

Comments

@s-celles
Copy link

s-celles commented Feb 6, 2022

Hello,

I bought a 5 buttons keypad like https://fr.aliexpress.com/item/2044851328.html?gatewayAdapt=glo2fra&spm=a2g0o.9042311.0.0.277c6c37tAJ6Zn

and run the following code

#include <ezAnalogKeypad.h>
// #include <Keyboard.h>

#define PIN_ANALOG_KEYPAD_5BUT A0

ezAnalogKeypad keypad_5but(PIN_ANALOG_KEYPAD_5BUT);

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

  keypad_5but.setNoPressValue(1023);  // analog value when no key is pressed
  keypad_5but.registerKey('w', 145);  // sw2 (up) 119
  keypad_5but.registerKey('z', 330);   // sw3 (down) 122
  keypad_5but.registerKey('a', 0);   // sw1 (left) 97
  keypad_5but.registerKey('d', 506);   // sw4 (right) 100
  keypad_5but.registerKey('s', 742);   // sw5 (but) 115

  keypad_5but.setDebounceTime(100);

  // Keyboard.begin();
}

void loop() {
  //Serial.println(analogRead(PIN_ANALOG_KEYPAD_5BUT));

  unsigned char button_k5 = keypad_5but.getKey();
  if (button_k5) {
    Serial.print("The button ");
    Serial.print(char(button_k5));
    Serial.println(" is pressed");
    switch (button_k5) {
      case 'w':
        Serial.println("UP");
        //Keyboard.press(KEY_UP_ARROW);
        break;
      case 'z':
        Serial.println("DOWN");
        //Keyboard.press(KEY_DOWN_ARROW);
        break;
      case 'a':
        Serial.println("LEFT");
        //Keyboard.press(KEY_LEFT_ARROW);
        break;
      case 'd':
        Serial.println("RIGHT");
        //Keyboard.press(KEY_RIGHT_ARROW);
        break;
      case 's':
        Serial.println("p");
        //Keyboard.press('p');
        break;
      default:
        break;
    }
    delay(100);
    //Keyboard.releaseAll();
  }
}

when pressing SW1 (left arrow) the following text is shown on console

The button a is pressed
LEFT
The button z is pressed
DOWN

I was expecting only

The button a is pressed
LEFT

I don't uderstand why DOWN is also displayed.

Any idea? is it a problem with the library ?

Kind regards

PS : library works fine with analog 4x4 keypad https://github.com/scls19fr/condor_sim_keypad_4x4

@ArduinoGetStarted
Copy link
Owner

Hello,
Did you do the calibration to get the exact value when no key is pressed and when each key is pressed ?

@s-celles
Copy link
Author

s-celles commented Feb 8, 2022

Yes I did it and when no key is pressed I get 1023
145 when SW2 (up) key is pressed ...

@ArduinoGetStarted
Copy link
Owner

@scls19fr I am sorry for the late reply.
I tried to find the reason but I cannot find any clue. The source code seem to be ok. It will keep this issue open. If someone else meets the same issue, I will order the keypad to check if there is any problem with the hardware.

Have a great day!

@s-celles
Copy link
Author

Thanks @ArduinoGetStarted
If tolerance was a variable changing it would be easier and I could try with a different value (smaller).
I haven't try changing it directly from 100 to 20 (for example) into your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants