16 December 2021
multiple buttons on a single pin

Product reference: https://s.click.aliexpress.com/e/_DDDNqrF

With the help of certain modules, it is possible to use multiple buttons connected to a single pin in your Arduino project. To make the process of reading button clicks more convenient, there is a useful library called AceButton available that simplifies the process of detecting button presses. This library requires you to specify a resistance value for each button, which is used to interpret the signal and map it to a corresponding action in your program. By using AceButton and configuring the resistances correctly, you can easily incorporate multiple buttons into your Arduino project and control various aspects of your hardware with ease.

Source code viewer
  1. static const uint8_t BUTTON_PIN = A5;
  2. static const uint8_t NUM_LEVELS = NUM_BUTTONS + 1;
  3. static const uint16_t LEVELS[NUM_LEVELS] = {
  4. // Replace these values with your corresponding values:
  5. 0 /* left */,
  6. 30 /* up */,
  7. 86 /* down */,
  8. 165 /* rigth */,
  9. 351 /* SW5 */,
  10. 1023 /* nothing pressed */,
  11. };
  12. static LadderButtonConfig buttonConfig(
  13. BUTTON_PIN, NUM_LEVELS, LEVELS, NUM_BUTTONS, BUTTONS
  14. );
  15.  
  16. void loop () {
  17. // Using this you can read the values while you hold down buttons from Tools > Serial monitor in Arduino IDE.
  18. Serial.println(analogRead(BUTTON_PIN));
  19. }
  20.  
Programming Language: C++