Frästisch mit elektronischer Höhenverstellung mittels Schrittmotoren.
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RotaryControler.cpp 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * RotaryControler.cpp
  3. *
  4. * Created on: 04.02.2022
  5. * Author: FSmilari
  6. */
  7. #include "RotaryControler.h"
  8. /*****************
  9. ** Constructors.
  10. ****************/
  11. RotaryControler::RotaryControler(int RotEnc_Dta_Pin, int RotEnc_Clk_Pin, int RotEnc_Switch_Pin) : Encoder(RotEnc_Dta_Pin, RotEnc_Clk_Pin,
  12. RotaryEncoder::LatchMode::FOUR3), RotarySwitch(RotEnc_Switch_Pin, true, 2000) {
  13. position = 0;
  14. Encoder.setPosition(position);
  15. }
  16. /******************
  17. ** Public methods
  18. *****************/
  19. void RotaryControler::tick(void) {
  20. Encoder.tick();
  21. }
  22. void RotaryControler::resetPosition(void) {
  23. Encoder.setPosition(0L);
  24. }
  25. long RotaryControler::getPosition(void) {
  26. return Encoder.getPosition();
  27. }
  28. int RotaryControler::getDirection(void) {
  29. return (int) Encoder.getPosition();
  30. }
  31. bool RotaryControler::isSwitchPressed(void) {
  32. return RotarySwitch.isPressed();
  33. }
  34. bool RotaryControler::isSwitchLongPressed(void) {
  35. return RotarySwitch.isLongPressed();
  36. }
  37. void RotaryControler::setDebounceTime(unsigned long time) {
  38. RotarySwitch.setDebounceTime(time);
  39. }
  40. void RotaryControler::loop(void) {
  41. RotarySwitch.loop();
  42. Encoder.tick();
  43. }
  44. RotaryEncoder::Direction RotaryControler::getEncoderMove() {
  45. long newPos = Encoder.getPosition();
  46. RotaryEncoder::Direction dir = Encoder.getDirection();
  47. if (position != newPos) {
  48. Serial.print("pos:");
  49. Serial.print(newPos);
  50. Serial.print(" dir:");
  51. Serial.println((int) dir);
  52. position = newPos;
  53. }
  54. return dir;
  55. }