Re: Greater than and less than in same command code
You actually have most of the psuedocode already taken care of, which is good:
To convert this to real code, we will first convert it to psuedocode:
Now that we have the psuedocode, we can start filling in with actual command lines. To read the sonar value, we will use the SensorValue command. Less than a value will use the less than symbol <, while greater than will use the greater than symbol >. Finally, since we need the value to be both less than 20 AND greater than 10, we will use the AND operator &&.
Finally, we need to decide what happens if the sonar value is greater than the highest value (20) and what happens if the sonar value is less than the lowest value (10). We can use the "else if" conditions to check for these other conditions
There is one more, unique condition that you will have to check for. When a Cortex sonar sensor is first initialized or when it receives no echo back (if there are no objects in range), it will return a value of -1. You will need to check for this in the 'greater than 20' else if using the OR operator || (if the value of the sonar is greater than 20 OR -1, move to position 2). To compare for an exact value (EQUAL TO), you will need to use the double-equal signs comparator, ==.
Let us know if you have any other questions, and be sure to take a look through the VEX Cortex Video Trainer for more help on how to use the boolean operators in if/else statements (specifically, under the Movement -> Automated Straightening section, but it's always good to go through the entire curriculum if you need a refresher): http://www.education.rec.ri.cmu.edu/pro ... index.html
Check out our Blog
! And our Facebook page
Need help? Take a look at our Wiki
and our Forums.I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody