ESC.cpp 946 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* Electronic Speed Controller (ESC) - Library */
  2. /*
  3. */
  4. #include "ESC.h"
  5. // < Constructor >
  6. /* Sets the proper pin to output.
  7. */
  8. ESC::ESC(byte ESC_pin, int outputMin, int outputMax, int armVal)
  9. {
  10. oPin = ESC_pin;
  11. oMin = outputMin;
  12. oMax = outputMax;
  13. oArm = armVal;
  14. }
  15. // < Destructor >
  16. ESC::~ESC()
  17. {
  18. // Nothing to destruct
  19. }
  20. // calib
  21. /* Calibrate the maximum and minimum PWM signal the ESC is expecting
  22. */
  23. void ESC::calib(void)
  24. {
  25. myESC.attach(oPin); // attaches the ESC on pin oPin to the ESC object
  26. myESC.writeMicroseconds(oMax);
  27. delay(ESC_CAL_DELAY);
  28. myESC.writeMicroseconds(oMin);
  29. delay(ESC_CAL_DELAY);
  30. arm();
  31. }
  32. void ESC::arm(void)
  33. {
  34. myESC.attach(oPin); // attaches the ESC on pin oPin to the ESC object
  35. myESC.writeMicroseconds (oArm);
  36. }
  37. void ESC::stop(void)
  38. {
  39. myESC.writeMicroseconds (ESC_STOP_PULSE);
  40. }
  41. void ESC::speed(int outputESC)
  42. {
  43. oESC = constrain(outputESC, oMin, oMax);
  44. myESC.writeMicroseconds(oESC);
  45. }