View unanswered posts | View active topics It is currently Wed Jul 17, 2019 8:39 pm

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Any number between this and this?
Author Message
Rookie

Joined: Mon Dec 15, 2014 9:48 pm
Posts: 16
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
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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!

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

Wed Feb 04, 2015 10:01 pm
Rookie

Joined: Mon Dec 15, 2014 9:48 pm
Posts: 16
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!

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
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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!

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
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

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

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning