Go Down

Topic: problem rc receiver signal (Read 2 times) previous topic - next topic

mustang493

Jan 23, 2013, 11:50 pm Last Edit: Jan 24, 2013, 12:16 am by mustang493 Reason: 1
Can anyone see anything wrong with this simple code.  Arduino uno,  expect the LED on pin 13 to be on or of dependant on the position of the control stick on the rc transmitter.  regardless of the stick position the LED remains on.

Code: [Select]
int rcpin =7;
int motpin = 13;

void setup() {
 Serial.begin(9600);
 pinMode(rcpin, INPUT);
 pinMode(motpin, OUTPUT);
 
}

int val;

void loop()

{
 val = pulseIn(rcpin, INPUT);
 Serial.println(val);
 delay(1000);
 if ((val > 14535) && (val < 14335)) {
   digitalWrite(motpin, LOW);
 }
 else {
   digitalWrite(motpin, HIGH);
 }
}


the value is changing when the rc transmitter switch is operated.  mid value is 14435 with the full deflections reading 14072 + or - a couple of points and 14926  + or - respectively

mustang493

#1
Jan 24, 2013, 12:09 am Last Edit: Jan 24, 2013, 12:17 am by mustang493 Reason: 1
the three stick positions are giving me three values 14072, 14435 and 14925 (plus or minus 1-6)

KeithRB

You have( (val >14335) && (val <14335)) since it cannot be both at once, it will always be false.

johncc


You have( (val >14335) && (val <14335)) since it cannot be both at once, it will always be false.


Typo on the numbers, but nice catch!!

That's why I usually format these things something like:
   if ( 14335 < val && val << 14535) {...

mustang493

in mid position it is neither therefore the else statement is true??

Go Up