Display SSD1306 for ESP32
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.

82 lines
1.5 KiB

  1. class Keyboard{
  2. private:
  3. byte goTo;
  4. byte goBack;
  5. byte plus;
  6. byte minus;
  7. byte debounceTime;
  8. Screen *screen;
  9. public:
  10. //Keyboard constructor
  11. Keyboard(byte goTo, byte goBack, byte plus, byte minus, byte debounceTime, Screen * screen){
  12. this->goTo = goTo;
  13. this->goBack = goBack;
  14. this->plus = plus;
  15. this->minus = minus;
  16. this->debounceTime = debounceTime;
  17. this->screen = screen;
  18. pinMode(goTo, INPUT_PULLUP);
  19. pinMode(goBack, INPUT_PULLUP);
  20. pinMode(plus, INPUT_PULLUP);
  21. pinMode(minus, INPUT_PULLUP);
  22. }
  23. //Debouncing functions
  24. void checkGoTo(){
  25. static char cont;
  26. if(digitalRead(this->goTo) == LOW)
  27. cont++;
  28. else
  29. cont = 0;
  30. if(cont == debounceTime/REFRESH){
  31. this->screen->goTo();
  32. }
  33. }
  34. void checkGoBack(){
  35. static char cont;
  36. if(digitalRead(this->goBack) == LOW){
  37. cont++;
  38. }
  39. else
  40. cont = 0;
  41. if(cont == debounceTime/REFRESH){
  42. this->screen->goBack();
  43. }
  44. }
  45. void checkPlus(){
  46. static char cont;
  47. if(digitalRead(this->plus) == LOW)
  48. cont++;
  49. else
  50. cont = 0;
  51. if(cont == debounceTime/REFRESH){
  52. this->screen->plusAction();
  53. }
  54. }
  55. void checkMinus(){
  56. static char cont;
  57. if(digitalRead(this->minus) == LOW)
  58. cont++;
  59. else
  60. cont = 0;
  61. if(cont == debounceTime/REFRESH){
  62. this->screen->minusAction();
  63. }
  64. }
  65. // All buttons are checked with this method
  66. void control(){
  67. this->checkGoTo();
  68. this->checkGoBack();
  69. this->checkPlus();
  70. this->checkMinus();
  71. }
  72. };