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.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. * Copyright (c) 2017 Victor Perez
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. *
  22. */
  23. #pragma once
  24. // Pin number of unattached pins
  25. #define NOT_ATTACHED (-1)
  26. #define INVALID_SERVO 255
  27. #ifndef MAX_SERVOS
  28. #define MAX_SERVOS 3
  29. #endif
  30. #define SERVO_DEFAULT_MIN_PW 544
  31. #define SERVO_DEFAULT_MAX_PW 2400
  32. #define SERVO_DEFAULT_MIN_ANGLE 0
  33. #define SERVO_DEFAULT_MAX_ANGLE 180
  34. #define HAL_SERVO_LIB libServo
  35. class libServo {
  36. public:
  37. libServo();
  38. bool attach(const int32_t pin, const int32_t minAngle=SERVO_DEFAULT_MIN_ANGLE, const int32_t maxAngle=SERVO_DEFAULT_MAX_ANGLE);
  39. bool attached() const { return pin != NOT_ATTACHED; }
  40. bool detach();
  41. void move(const int32_t value);
  42. int32_t read() const;
  43. private:
  44. void servoWrite(uint8_t pin, const uint16_t duty_cycle);
  45. uint8_t servoIndex; // index into the channel data for this servo
  46. int32_t pin = NOT_ATTACHED;
  47. int32_t minAngle;
  48. int32_t maxAngle;
  49. int32_t angle;
  50. bool setupSoftPWM(const int32_t pin);
  51. void pauseSoftPWM();
  52. void pwmSetDuty(const uint16_t duty_cycle);
  53. };