Advertisement
wrighizilla

2ch servo steering en 3.0

Apr 28th, 2020
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. /* this application allow to control a rear servo with 2ch radio.
  2. before start you need arduino program and driver CH341SER.
  3. radio value are normally 1000 to 2000 center 1500
  4. but before is better check your endpoint with serial monitor in arduino ide
  5. to check signal void copy it in a new tab this sketc below and check values write in
  6. serial monitor by moving trasmitter wheel or stick
  7.  
  8.  
  9. int rxpulse;
  10. void setup() {
  11. Serial.begin(9600);
  12. }
  13. void loop() {
  14. rxpulse = pulseIn(8, HIGH); //-- per sapere qual'è il valore del segnale di sterzo
  15. Serial.println(rxpulse);
  16. }
  17.  
  18. after you can fill better your sketch with your tx right values signal from front steering
  19. check also your bec because 2 servos sometimes more need power or an external bec.
  20.  
  21. as is show you have to set your custom parameters in define list
  22. */
  23. #define antsx 1000 //-- in front servo endpoint sx
  24. #define antdx 2000 //-- in front servo endpoint dx
  25. #define postsx 30//-- out rear servo sx if inverted with postdx it reverse
  26. #define postdx 150 //-- out rear servo dx if inverted with postsx it reverse
  27. #define centro 0 //-- add or subtract xx value to center steering
  28. #define tolerance 5 //-- if your poor quality servo vibrates try 5
  29. #include <Servo.h>
  30. Servo myservo;
  31. unsigned int rxpulse;
  32. unsigned int newPos, oldPos;
  33. void setup() {
  34. myservo.attach(10); //-- rear servo signal out pin
  35. pinMode(8, INPUT); //-- front servo signal in pin
  36. }
  37. void loop() {
  38. rxpulse = pulseIn(8, HIGH);
  39. newPos = map(pulseIn(8, HIGH), antsx, antdx,postsx, postdx);
  40. if (abs (newPos - oldPos)> tolerance) {
  41. oldPos = newPos;
  42.  
  43. myservo.write(newPos + centro);
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement