Hi,
I'm quite new to this arduino, so maybe my approach is wrong, or can somebody explain why it is not working as requested.
The aim of my project is to decode a PPM sum signal from a RC control, add two channels and put it together back to a PPM sum signal.
It's basically working, but there is some space for improvement.
Ive attached a snip how it actually looks like.
Green is my PPM sum signal input, Red my output.
here's my code:
#define channumber 5 //How many channels have your radio?
#define signalan 300
int value[channumber];
int var4 = 0;
int var5 = 0;
int time = 0;
void setup()
{
pinMode(3, INPUT); //Pin 3 as input
pinMode(4, INPUT); //pin 4 as input
pinMode(5, INPUT); //pin 5 as input
pinMode(6, OUTPUT); //pin6 as output
}
void loop()
{
while(pulseIn(3, LOW) <= 2000){} //Wait for the beginning of the frame
for(int x=0; x<=channumber-3; x++)//Loop to store all the channel position
{
value[x]=pulseIn(3, LOW);
}
var4 = digitalRead(4);
if (var4 == HIGH)//check channel 4 short oder long
{
value[3]=1700;
}
else
{
value[3]=1000;
}
var5 = digitalRead(5);
if (var5 == HIGH) //check channel 5 short oder long
{
value[4]=1700;
}
else
{
value[4]=1000;
}
for (int x=0; x<=channumber-1; x++)//Loop to create PPM signal
{
digitalWrite(6, HIGH);
delayMicroseconds(signalan);
digitalWrite(6, LOW);
delayMicroseconds(value[x]);
}
digitalWrite(6, HIGH);
delayMicroseconds(signalan);
digitalWrite(6, LOW);
}
The issue is that it's missing always the second input signal even the time at "while(pulseIn(3, LOW) <= 2000) " is higher to get out of the while loop.
this just works at the second turn. it seems like it needs the falling down of the input to start counting.
Is there a way to change this that its allready grabbing the next signal chain?
If i just set at the end of the code some other port (e.g. 2 as output) to high and connect it directly to pin 3 it's not working at all.
I modified the code in this way:
void setup()
{
pinMode(3, INPUT); //Pin 3 as input
pinMode(4, INPUT); //pin 4 as input
pinMode(5, INPUT); //pin 5 as input
pinMode(6, OUTPUT); //pin6 as output
while(pulseIn(3, LOW) <= 5000){} //Wait for the beginning of the frame
}
void loop()
{
for(int x=0; x<=channumber-3; x++)//Loop to store all the channel position
{
value[x]=pulseIn(3, LOW);
}
this works due to the fact, my whole sequence is short enough.
But is there a way, how to make this in better?
This just i've once the snychronisation and then i'm begging that it never gets lost.
Due to the fact that maybe i want to have a sixth or seventh channel i maybe get screwed up.
The reason why i dont use a bigger remote control is that this is for a car and i want to use the car remote control, not the ones for flight and currently there are maximum 4 channels available.

