My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

Servo.h 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #pragma once
  23. #include <Arduino.h>
  24. class Servo {
  25. static const int MIN_ANGLE = 0,
  26. MAX_ANGLE = 180,
  27. MIN_PULSE_WIDTH = 544, // Shortest pulse sent to a servo
  28. MAX_PULSE_WIDTH = 2400, // Longest pulse sent to a servo
  29. TAU_MSEC = 20,
  30. TAU_USEC = (TAU_MSEC * 1000),
  31. MAX_COMPARE = ((1 << 16) - 1), // 65535
  32. CHANNEL_MAX_NUM = 16;
  33. public:
  34. Servo();
  35. int8_t attach(const int pin); // attach the given pin to the next free channel, set pinMode, return channel number (-1 on fail)
  36. void detach();
  37. void write(int degrees); // set angle
  38. void move(const int degrees); // attach the servo, then move to value
  39. int read(); // returns current pulse width as an angle between 0 and 180 degrees
  40. private:
  41. static int channel_next_free;
  42. int channel;
  43. int pin;
  44. int degrees;
  45. };