Go Down

### Topic: Comparing variables and choosing highest (Read 269 times)previous topic - next topic

#### ac21

##### May 16, 2016, 08:08 am
Code: [Select]
`void switchrx(){     if ((rx1rssi > rx2rssi + 10) || (rx1rssi > rx3rssi + 10)) {              Serial.println("SWITCH to 1 ================" );              digitalWrite(rx2out, LOW);                digitalWrite(rx3out, LOW);                              delay(5);                           digitalWrite(rx1out, HIGH);                  delay(1000);   }   else if ((rx2rssi > rx1rssi + 10) || (rx2rssi > rx3rssi + 10)) {              Serial.println("SWITCH to 2 ================" );                  digitalWrite(rx1out, LOW);                digitalWrite(rx3out, LOW);                              delay(5);                           digitalWrite(rx2out, HIGH);                  delay(1000);    }         else if ((rx3rssi > rx2rssi + 10) || (rx3rssi > rx1rssi + 10)) {              Serial.println("SWITCH to 3 ================" );                  digitalWrite(rx1out, LOW);                digitalWrite(rx2out, LOW);                              delay(5);                           digitalWrite(rx3out, HIGH);                  delay(1000);       }     }    `

Imagine rx1rssi, 2 and 3 are buckets of water and if one of those buckets gets filled with water more then 10 oz then the others I want dump that bucket.

above is the code i have, but how it is now if rx1rssi is more then rx2rssi, rx1rssi will dump without caring what rx3rssi is.    How can i compare all three?

#### ac21

#1
##### May 16, 2016, 08:30 am
This works, is there a better way to do it?

Code: [Select]
`void switchrx(){if (rx1rssi > rx2rssi + 10){if (rx1rssi > rx3rssi + 10){              Serial.println("SWITCH to 1 ================" );              digitalWrite(rx2out, LOW);                digitalWrite(rx3out, LOW);                              delay(5);                           digitalWrite(rx1out, HIGH);                  delay(1000);      }}if (rx2rssi > rx1rssi + 10){if (rx2rssi > rx3rssi + 10){              Serial.println("SWITCH to 2 ================" );              digitalWrite(rx1out, LOW);                digitalWrite(rx3out, LOW);                              delay(5);                           digitalWrite(rx2out, HIGH);                  delay(1000);      }}if (rx3rssi > rx2rssi + 10){if (rx3rssi > rx1rssi + 10){              Serial.println("SWITCH to 3 ================" );              digitalWrite(rx2out, LOW);                digitalWrite(rx1out, LOW);                              delay(5);                           digitalWrite(rx3out, HIGH);                  delay(1000);      }}  `

#### spirit

#2
##### May 16, 2016, 08:40 am
Quote
This works, is there a better way to do it?
your previous code, only you need to replace the || OR with a && AND sign.

#### UKHeliBob

#3
##### May 16, 2016, 08:43 am
How about putting the RSSI values in an array and iterating through it to find the highest ?

A diversity receiver I imagine ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

#### ac21

#4
##### May 16, 2016, 11:50 pm
your previous code, only you need to replace the || OR with a && AND sign.
there was some issue with that I also don't see it now.

How about putting the RSSI values in an array and iterating through it to find the highest ?

A diversity receiver I imagine ?
I'm not familiar with working with arrays.

Yes I'm using three RC305(rx5808) with the rssi pin tapped into. If you are interested I can provide more detail.

#### Delta_G

#5
##### May 17, 2016, 12:26 am
I'm not familiar with working with arrays.
Then what a great time to learn.  It's not terribly hard.  Use google to find a tutorial on arrays in C++.  There are plenty.  Read a few of them.
If at first you don't succeed, up - home - sudo - enter.

#### ac21

#6
##### May 17, 2016, 02:15 am
Then what a great time to learn.  It's not terribly hard.  Use google to find a tutorial on arrays in C++.  There are plenty.  Read a few of them.
I was gonna get to it but I guess now is a great time
Thank you Sir

Go Up