ppm reading not working

Hi, I found a piece of code from this website: https://www.instructables.com/id/Reading-RC-Receiver-PPM-Signal-Using-Arduino/
I copy and pasted the code, and used it with my arduino nano, fs-iA6b reciever, and a flysky fs-i6x reciever. The code didn't work well. I noticed that there was a lot of noise and large fluctuation in the readings. Also, there was quite a bit of delay. The only time it worked well was when I would position the sticks on my transmitter so that all of the channel values were zero, and move each joystick separately.

I changed the code a little bit with some one milisecond delays:

unsigned long int a,b,c;
int x[15],ch1[15],ch[7],i;
//specifing arrays and variables to store values 

void setup() {
Serial.begin(9600);
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2), read_me, FALLING);
  // enabling interrupt at pin 2
}

void loop() {
read_rc();

Serial.print(ch[1]);Serial.print("\t");
Serial.print(ch[2]);Serial.print("\t");
Serial.print(ch[3]);Serial.print("\t");
Serial.print(ch[4]);Serial.print("\t");
Serial.print(ch[5]);Serial.print("\t");
Serial.print(ch[6]);Serial.print("\n");

delay(100);
}


void read_me()  {
 //this code reads value from RC reciever from PPM pin (Pin 2 or 3)
 //this code gives channel values from 0-1000 values 
 //    -: ABHILASH :-    //
a=micros(); //store time value a when pin value falling
c=a-b;      //calculating time inbetween two peaks
b=a;// 
x[i]=c;     //storing 15 value in array
i=i+1;

if(i==15){
  for(int j=0;j<15;j++){
    ch1[j]=x[j];
    delay(1);
    }
             i=0;}}//copy store all values from temporary array another array after 15 reading  

void read_rc(){
int i,j,k=0;
  for(k=14;k>-1;k--){//k = 14
    if(ch1[k]>10000){
      j=k;
      delay(1);
      }}//detecting separation space 10000us in that another array //delay
                          
  for(i=1;i<=6;i++){ //i = 6
    ch[i]=(ch1[i+j]-1000);
    delay(1);
    }}
    //assign 6 channel values after separation space

The readings were much better and more accurate without much delay. However the problem is that the last two channel readings were irrespective to any change and remained constant (second last channel value stayed at -1000 and the last channel value stayed at -500). Is there a way to fix this? Maybe by adding 2 more channels to the readings?

12341234tmmt:
Hi, I found a piece of code from this website: https://www.instructables.com/id/Reading-RC-Receiver-PPM-Signal-Using-Arduino/
I copy and pasted the code, and used it with my arduino nano, fs-iA6b reciever, and a flysky fs-i6x reciever. The code didn't work well. I noticed that there was a lot of noise and large fluctuation in the readings. Also, there was quite a bit of delay. The only time it worked well was when I would position the sticks on my transmitter so that all of the channel values were zero, and move each joystick separately.

I changed the code a little bit with some one milisecond delays:

unsigned long int a,b,c;

int x[15],ch1[15],ch[7],i;
//specifing arrays and variables to store values

void setup() {
Serial.begin(9600);
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2), read_me, FALLING);
  // enabling interrupt at pin 2
}

void loop() {
read_rc();

Serial.print(ch[1]);Serial.print("\t");
Serial.print(ch[2]);Serial.print("\t");
Serial.print(ch[3]);Serial.print("\t");
Serial.print(ch[4]);Serial.print("\t");
Serial.print(ch[5]);Serial.print("\t");
Serial.print(ch[6]);Serial.print("\n");

delay(100);
}

void read_me()  {
//this code reads value from RC reciever from PPM pin (Pin 2 or 3)
//this code gives channel values from 0-1000 values
//    -: ABHILASH :-    //
a=micros(); //store time value a when pin value falling
c=a-b;      //calculating time inbetween two peaks
b=a;//
x[i]=c;    //storing 15 value in array
i=i+1;

if(i==15){
  for(int j=0;j<15;j++){
    ch1[j]=x[j];
    delay(1);
    }
            i=0;}}//copy store all values from temporary array another array after 15 reading

void read_rc(){
int i,j,k=0;
  for(k=14;k>-1;k--){//k = 14
    if(ch1[k]>10000){
      j=k;
      delay(1);
      }}//detecting separation space 10000us in that another array //delay
                         
  for(i=1;i<=6;i++){ //i = 6
    ch[i]=(ch1[i+j]-1000);
    delay(1);
    }}
    //assign 6 channel values after separation space




The readings were much better and more accurate without much delay. However the problem is that the last two channel readings were irrespective to any change and remained constant (second last channel value stayed at -1000 and the last channel value stayed at -500). Is there a way to fix this? Maybe by adding 2 more channels to the readings?

You should use millis() instead of delay().

unsigned long timestamp=0;
if(millis()-timestamp>=1000){
//code to run after timer expires
timestamp=millis();
}

I tried your suggestion, and the it didn't quite change the result.

Something else I should have point out is that the last channel is reading the negative values and the inverse values of the first channel. so the last channel is reading -1000 when the first channel is 0

unsigned long timestamp=0;
unsigned long int a,b,c;
int x[15],ch1[15],ch[7],i;
//specifing arrays and variables to store values 

void setup() {
Serial.begin(9600);
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2), read_me, FALLING);
  // enabling interrupt at pin 2
}

void loop() {
read_rc();

Serial.print(ch[1]);Serial.print("\t");
Serial.print(ch[2]);Serial.print("\t");
Serial.print(ch[3]);Serial.print("\t");
Serial.print(ch[4]);Serial.print("\t");
Serial.print(ch[5]);Serial.print("\t");
Serial.print(ch[6]);Serial.print("\n");

delay(100);
}


void read_me()  {
 //this code reads value from RC reciever from PPM pin (Pin 2 or 3)
 //this code gives channel values from 0-1000 values 
 //    -: ABHILASH :-    //
a=micros(); //store time value a when pin value falling
c=a-b;      //calculating time inbetween two peaks
b=a;// 
x[i]=c;     //storing 15 value in array
i=i+1;

if(i==15){
  for(int j=0;j<15;j++){
    ch1[j]=x[j];
    delay(1);
    }
             i=0;}}//copy store all values from temporary array another array after 15 reading  

void read_rc(){
int i,j,k=0;
  for(k=14;k>-1;k--){//k = 14
    if(ch1[k]>10000){
      j=k;
      if(millis()-timestamp>=1000){
        //code to run after timer expires
        timestamp=millis();
        };
      }}//detecting separation space 10000us in that another array //delay
                          
  for(i=1;i<=6;i++){ //i = 6
    ch[i]=(ch1[i+j]-1000);
    if(millis()-timestamp>=1000){
        //code to run after timer expires
        timestamp=millis();
        };
    }}
    //assign 6 channel values after separation space

this was the new code

This code wasn't working so I used a new code to read the ppm signals from this link:
[u]Read PPM signals from RC receiver or Control - Exhibition - Arduino Forum