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);
 Serial.println(val);
// if ((val > 14535) && (val < 14335))
if ( 14335 < val || val < 14535) {
  digitalWrite(motpin, LOW);
 }
 else {
  digitalWrite(motpin, HIGH);
 }
}
KeithRB:
You have an && there when you want an || (or).
And says if either is false, the result is false.
Or says if either is true, the result is true.
mustang493:
in mid position it is neither therefore the else statement is true??
if ( 14335 < val && val < 14535) // means "if val is between 14335 and 14535
if ( val > 14535) || (val < 14335) ) // means "if val is NOT between 14335 and 14535
if ( 14535 < val || val < 14335) // ditto: "if val is NOT between 14335 and 14535
int rcpin =7;
int motpin = 13;
const int THRESHOLD = 5;
void setup() {
 Serial.begin(9600);
 pinMode(rcpin, INPUT);
 pinMode(motpin, OUTPUT);
Â
}
int val;
void loop()
{
 val = pulseIn(rcpin, INPUT);
 Serial.println(val);
 delay(1000);
 Serial.println(val);
// if ((val > 14535) && (val < 14335))
//if ( 14335 < val || val > 14535)
if ( (val > 14435 - THRESHOLD) && (val < 14435 + THRESHOLD) )
{
  digitalWrite(motpin, LOW);
 }
 else {
  digitalWrite(motpin, HIGH);
 }
}
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.
KeithRB:
exactly. All the other code required the servo to read exactly 14335.
I never saw any code of the OPs of the form ( (14335 ? val) ?? (val ? 14335)), other than your reply to OP which I thought was a typo and Arrch's misreading of it. Did OP edit his 14335/14535s in the original post?
Guys thanks for all your help on this, it's late here in the UK so calling it a day. i'll run the code and try and get a better understanding. fantastic forum and thanks for helping me out.
mustang493:
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?
 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