DIY fertilizer mixer and plant watering machine https://www.xythobuz.de/giessomat.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Keymatrix.h 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef _KEYMATRIX_H_
  2. #define _KEYMATRIX_H_
  3. #include <CircularBuffer.h>
  4. class Keymatrix {
  5. public:
  6. class Event {
  7. public:
  8. enum EventType {
  9. button_down,
  10. button_up,
  11. no_event
  12. };
  13. Event(EventType _type, int _row, int _col);
  14. EventType getType(void);
  15. int getRow(void);
  16. int getCol(void);
  17. // helper for 4x3 telephone keypad
  18. // -1 is *, -2 is #, or digits 0-9
  19. int getNum(void);
  20. private:
  21. EventType type;
  22. int row, col;
  23. };
  24. Keymatrix(int _rows, int _cols);
  25. ~Keymatrix(void);
  26. // first rows, then cols
  27. void setPins(int _pins[]);
  28. void setDebounce(unsigned long ms);
  29. void scan(void);
  30. bool hasEvent(void);
  31. Event getEvent(void);
  32. private:
  33. unsigned long debounce;
  34. const static unsigned long default_debounce = 5;
  35. unsigned long last_scan_time;
  36. int rows, cols;
  37. int *pins;
  38. bool *lastPressed;
  39. bool *lastState;
  40. CircularBuffer<Event *, 32> events;
  41. };
  42. #endif // _KEYMATRIX_H_