Go Down

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

johncc


sorry guys i can't get my head round this..  i thought if i use val > 14335 it would work for any value greater than 14335 regardless of wether the value moves slightly.

Hard to get your head around because you've gotten a lot of ideas, and some from every one of us has been wrong in one way or the other :)
You could probably understand better if you broke it up like this?
Code: [Select]

  if (val > 15555){
     // joystick is FORWARD
  }
  else if (val < 14444) {
     // joystick is REARWARD
  }
  else {
     // joystick is NEUTRAL
  }



I changed the numbers so we would quit misreading 14335/14535 :) 

PaulS

Quote
I changed the numbers so we would quit misreading 14335/14535

Actually, this is a perfect illustration of why magic numbers are a bad idea.

Code: [Select]
#define LOW_VAL 14335
#define HIGH_VAL 14535

if(val < LOW_VAL)
{
}
else if(val > HIGH_VAL)
{
}
else
{
}

means you correct an error/erroneous value in one place, and the logic is far easier to see.

johncc


Code: [Select]

if ( 14335 < val || val < 14535) {


Can be simplified to

Code: [Select]
if ( val != 14335) {

So you want the LED to be off at that value, and on otherwise? Seems a bit loft to expect it to be EXACTLY that value.


Actually I think that code simplifies to
Code: [Select]
if (val < 14535) {

Which is still in error, but not that error :)

johncc


Actually, this is a perfect illustration of why magic numbers are a bad idea.


Absolutely!

Go Up