Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* this application allow to control a rear servo with 2ch radio.
- before start you need arduino program and driver CH341SER.
- radio value are normally 1000 to 2000 center 1500
- but before is better check your endpoint with serial monitor in arduino ide
- to check signal void copy it in a new tab this sketc below and check values write in
- serial monitor by moving trasmitter wheel or stick
- int rxpulse;
- void setup() {
- Serial.begin(9600);
- }
- void loop() {
- rxpulse = pulseIn(8, HIGH); //-- per sapere qual'è il valore del segnale di sterzo
- Serial.println(rxpulse);
- }
- after you can fill better your sketch with your tx right values signal from front steering
- check also your bec because 2 servos sometimes more need power or an external bec.
- as is show you have to set your custom parameters in define list
- */
- #define antsx 1000 //-- in front servo endpoint sx
- #define antdx 2000 //-- in front servo endpoint dx
- #define postsx 30//-- out rear servo sx if inverted with postdx it reverse
- #define postdx 150 //-- out rear servo dx if inverted with postsx it reverse
- #define centro 0 //-- add or subtract xx value to center steering
- #define tolerance 5 //-- if your poor quality servo vibrates try 5
- #include <Servo.h>
- Servo myservo;
- unsigned int rxpulse;
- unsigned int newPos, oldPos;
- void setup() {
- myservo.attach(10); //-- rear servo signal out pin
- pinMode(8, INPUT); //-- front servo signal in pin
- }
- void loop() {
- rxpulse = pulseIn(8, HIGH);
- newPos = map(pulseIn(8, HIGH), antsx, antdx,postsx, postdx);
- if (abs (newPos - oldPos)> tolerance) {
- oldPos = newPos;
- myservo.write(newPos + centro);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement