Decoding RC transmitter and using all channels to turn on LED's

Iam trying to use all the channels in the RC radio to turn on LED's when moving each channel stick up and down. I can not make the if statements to work past the first one. I only have 1 channel here but can not seem to get it to work so I can add the rest. I am new to programming and have trouble with all the Curley brackets.

double channel[4];  

void setup() {
  pinMode(7,OUTPUT);
  pinMode(2,INPUT);
  Serial.begin(9600);
}

void loop() {
  channel[0] = pulseIn(2, HIGH);
 
Serial.print("-");

Serial.println(channel[0]);
Serial.print("-");

  if (channel[0] < 1300.00); 
    digitalWrite(7, HIGH);
  if (channel[0] > 1450.00); 
    digitalWrite(7, HIGH); 
    else
   digitalWrite(7, LOW);
  }

 



double channel[4];  

void setup() {
  pinMode(7,OUTPUT);
  pinMode(2,INPUT);
  Serial.begin(9600);
}



  
   

   
       

IF you use Google to search for "arduino pulseln", you will quickly find this:
" The length of the pulse (in microseconds) or 0 if no pulse started before the timeout. Data type: unsigned long..

That is not a float, so there is no reason to compare the return value to a float.
Paul

I am not having any trouble with reading the PWM signals from the receiver. I am having trouble with using more than one of the if statements
Thank You

That is exactly why I asked why your "if" statements contain float values when the return from pulsln() is an unsigned long, NOT a float. Fix that and perhaps your "if" will work better.
Paul

There are some extra semicolons.

Please review the syntax for the if/else statement.

    if (condition) {
      // code of condition is true
    }
    else {
      // code of condition false
    }

HTH

a7

Thank You for your help. I will give it a look

i I looked and I do not see any semicolons.

I finally got the programing to work for the first channel. Hope I can get the other channels.
If there is a better way to make this work I wood Shure like the help.
Thank You
MainRCradio2.ino (592 Bytes)

Please post the code you want help with.


Take another look, or google and remind yourself what a semicolon is.

This is how you wrote it:

  if (channel[0] < 1300.00); 
    digitalWrite(7, HIGH);
  if (channel[0] > 1450.00); 
    digitalWrite(7, HIGH); 
    else
   digitalWrite(7, LOW);
  }

It's this character ';'

And it is almost never what you mean or want when you put it at the end of the condition part of an if statement.

Because this one line is a complete and legal statement that amounts to… doing nothing:

    if (channel[0] < 1300.00); 

Welcome to C/C++. Spelling counts. Punctuation counts. Your eyesight will be challenged.

a7

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.