Hello guys,
I'm totally new to Arduino, this is my first project out of the 15 projects that came along with my kit.
I searched over the web but couldn't find an answer to my question.
I'm a longtime RC modelist from France (sorry for bad english ;)).
I own a Futaba 6J radio system with a Futaba R2006GS receiver, so it's a 6 channel system.
For the purpose of controlling a RC device truck with lots of functions I need 9 functions (not all at the same time), that's why I thought my Arduino Uno might be helpfull.
I would like to be able to flip a switch on the transmitter so that I can have two mods like mode1: driving and mode2: accessories.
To be clearer I would like 2 options.
Switch is off
ch1=>servo 1
ch2 =>servo 2
ch3 =>servo 3
ch4 =>servo 4
switch is flipped
ch1 =>servo 5
ch2 =>servo 6
ch3 =>servo7
ch4 =>servo 8
the switch is ch5.
I wrote the following code wich works but I end up with jitter in the servo wich I think is produced by the translation from PWM to time, then from time to angle and then sent back to the servo.
#include <Servo.h>
Servo myServoBlack;
Servo myServoOrange;
int ch5;
int ch4;
int angle;
void setup() {
myServoBlack.attach(3);
myServoOrange.attach(2);
pinMode(4, INPUT);
pinMode(5, INPUT);
Serial.begin(9600);
}
void loop() {
ch4 = pulseIn(4, HIGH, 25000);
ch5 = pulseIn(5, HIGH, 25000);
Serial.print("Channel 4: ");
Serial.print(ch4);
Serial.print(" , Channel 5: ");
Serial.print(ch5);
angle = map(ch4,1050,1950,0,179);
Serial.print(" , angle: ");
Serial.println(angle);
if(ch5 < 1500){
myServoBlack.write(angle);
myServoOrange.write (90);
}else if(ch5 > 1000) {
myServoBlack.write(90);
myServoOrange.write(angle);
}
delay(10);
}
Is there a way to avoid the jitter ?
Or something simpler like directly taking the value from the receiver with let's say input2 and sending it to output 3 or 4 depending of the position of the switch?
Hope it's clear
Thanks for your help!!