Skip to content

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

Description

@s-celles

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions