View unanswered posts | View active topics It is currently Fri Sep 21, 2018 1:34 pm






Reply to topic  [ 4 posts ] 
Any number between this and this? 
Author Message
Rookie

Joined: Mon Dec 15, 2014 9:48 pm
Posts: 16
Post Any number between this and this?
Hi,
We have some code that goes like this:

if ((SensorValue(SonarSensor2) > 23) && (SensorValue(SonarSensor1) == 23))//if sonar two is greater than 23 and sonar one is equal to 23 move forward
{
motor[motorC] = -20;
motor[motorD] = -20;
motor[motorE] = 20;
motor[motorF] = 20;
}

How can we make it like this:

if ((SensorValue(SonarSensor2) > any number 21 through 25) && (SensorValue(SonarSensor1) == any number 21 through 25))
{
motor[motorC] = -20;
motor[motorD] = -20;
motor[motorE] = 20;
motor[motorF] = 20;
}
What would we put for the "any number 21 through 25" part? Thanks! :P


Wed Feb 04, 2015 8:44 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: Any number between this and this?
Cyks wrote:
How can we make it like this:

if ((SensorValue(SonarSensor2) > any number 21 through 25) && (SensorValue(SonarSensor1) == any number 21 through 25))
{
motor[motorC] = -20;
motor[motorD] = -20;
motor[motorE] = 20;
motor[motorF] = 20;
}
What would we put for the "any number 21 through 25" part? Thanks! :P

That would be something like this:
Code:
if ((SensorValue[SonarSensor2] > 25) && (SensorValue[SonarSensor1) >= 21) && (SensorValue[SonarSensor1] <= 25))


Wed Feb 04, 2015 10:01 pm
Profile
Rookie

Joined: Mon Dec 15, 2014 9:48 pm
Posts: 16
Post Re: Any number between this and this?
MHTS wrote:
Cyks wrote:
How can we make it like this:

if ((SensorValue(SonarSensor2) > any number 21 through 25) && (SensorValue(SonarSensor1) == any number 21 through 25))
{
motor[motorC] = -20;
motor[motorD] = -20;
motor[motorE] = 20;
motor[motorF] = 20;
}
What would we put for the "any number 21 through 25" part? Thanks! :P

That would be something like this:
Code:
if ((SensorValue[SonarSensor2] > 25) && (SensorValue[SonarSensor1) >= 21) && (SensorValue[SonarSensor1] <= 25))

Thanks so much for your help! ^_^ One question tho, do the last two sensor statements need parenthesis around them?

Like this?:
if ((SensorValue[SonarSensor2] > 25) && ((SensorValue[SonarSensor1) >= 21) && (SensorValue[SonarSensor1] <= 25)))


Wed Feb 04, 2015 10:26 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
Post Re: Any number between this and this?
Cyks wrote:
MHTS wrote:
Cyks wrote:
How can we make it like this:

if ((SensorValue(SonarSensor2) > any number 21 through 25) && (SensorValue(SonarSensor1) == any number 21 through 25))
{
motor[motorC] = -20;
motor[motorD] = -20;
motor[motorE] = 20;
motor[motorF] = 20;
}
What would we put for the "any number 21 through 25" part? Thanks! :P

That would be something like this:
Code:
if ((SensorValue[SonarSensor2] > 25) && (SensorValue[SonarSensor1) >= 21) && (SensorValue[SonarSensor1] <= 25))

Thanks so much for your help! ^_^ One question tho, do the last two sensor statements need parenthesis around them?

Like this?:
if ((SensorValue[SonarSensor2] > 25) && ((SensorValue[SonarSensor1) >= 21) && (SensorValue[SonarSensor1] <= 25)))

No, they are all &&'s and have same precedence. It's like saying should I have 3 + (4 + 5) instead of 3 + 4 + 5.


Thu Feb 05, 2015 5:02 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.