Advertisement
Guest User

Untitled

a guest
Mar 30th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. #include <Servo.h>
  2. Servo ESC; // create servo object to control the ESC
  3. int potValue; // value from the analog pin
  4. void setup() {
  5. // Attach the ESC on pin 9
  6. ESC.attach(9,1000,2000); // (pin, min pulse width, max pulse width in microseconds)
  7.  
  8. ESC.write(2000);
  9. delay(2000);
  10. ESC.write(1000);
  11. delay(2000);
  12.  
  13. }
  14.  
  15. void calibrate(int ctr,int setfreq){
  16. int phaseL = 200;
  17. if(ctr < phaseL){ //mid
  18. // ESC.write(1500);
  19. }
  20. if(ctr > phaseL && ctr < phaseL*2){ //high
  21. ESC.write(2000);
  22. }
  23. if(ctr > phaseL*2 && ctr < phaseL*3){ //low
  24. ESC.write(1000);
  25. }
  26. if(ctr>phaseL*3){
  27. ESC.write(setfreq);
  28. }
  29. }
  30. int ctr = 0;
  31. void loop() {
  32. //potValue = analogRead(A0); // reads the value of the potentiometer (value between 0 and 1023)
  33. //potValue = map(potValue, 0, 1023, 0, 180); // scale it to use it with the servo library (value between 0 and 180)
  34. ESC.write(1100+ctr); // Send the signal to the ESC
  35. delay(100);
  36. ctr++;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement