View unanswered posts | View active topics It is currently Sun Nov 17, 2019 8:15 am






Reply to topic  [ 2 posts ] 
If Statement 
Author Message
Rookie

Joined: Sat Mar 21, 2015 2:41 pm
Posts: 1
Post If Statement
I made this program that has two variations
Code:
task autonomous()
{
        if((0<=SensorValue[Color]<2047)&&(2047<SensorValue[Side]<3071))            //Blue Right
           {
              RWheels(127,500,500);
           }
        if((0<=SensorValue[Color]<2047) && (0<=SensorValue[Side]<1023))           //Blue Left
           {
              ArmU(127,2100);
           }
        if((0<=SensorValue[Color]<2047) && (1023<SensorValue[Side]<2047))       //Blue Coop
           {
              ArmU(127,2100);
           }
        if((0<=SensorValue[Color]<2047) && (3071<SensorValue[Side]<=4095))         //Blue Auto
           {
              ArmU(127,2100);
           }
        if((2047<SensorValue[Color]<=4095) && (2047<SensorValue[Side]<3071))      //Red Right
           {
              ArmU(127,2100);
           }
        if((2047<SensorValue[Color]<=4095) && (0<=SensorValue[Side]<1023))         //Red Left
           {
              ArmU(127,2100);
           }
        if((2047<SensorValue[Color]<=4095) && (1023<SensorValue[Side]<2047))      //Red Coop
           {
              ArmU(127,2100);
           }
        if((2047<SensorValue[Color]<=4095)  && (3071<SensorValue[Side]<=4095))   //Red Auto
           {
              ArmU(127,2100);
           }
}
And
task autonomous()
{
   while(true)
   {
        if((0<=SensorValue[Color]<2047) && (2047<SensorValue[Side]<3071))            //Blue Right
           {
              RWheels(127,500,500);
           }
        if((0<=SensorValue[Color]<2047) && (0<=SensorValue[Side]<1023))           //Blue Left
           {
              ArmU(127,2100);
           }
        if((0<=SensorValue[Color]<2047) && (1023<SensorValue[Side]<2047))       //Blue Coop
           {
              ArmU(127,2100);
           }
        if((0<=SensorValue[Color]<2047) && (3071<SensorValue[Side]<=4095))         //Blue Auto
           {
              ArmU(127,2100);
           }
        if((2047<SensorValue[Color]<=4095) && (2047<SensorValue[Side]<3071))      //Red Right
           {
              ArmU(127,2100);
           }
        if((2047<SensorValue[Color]<=4095) && (0<=SensorValue[Side]<1023))         //Red Left
           {
              ArmU(127,2100);
           }
        if((2047<SensorValue[Color]<=4095) && (1023<SensorValue[Side]<2047))      //Red Coop
           {
              ArmU(127,2100);
           }
        if((2047<SensorValue[Color]<=4095)  && (3071<SensorValue[Side]<=4095))   //Red Auto
           {
              ArmU(127,2100);
           }
         }
}

The problem is that only the first if statement Runs
CAn anyone help me
I use Natural Language PLTW


Sat Mar 21, 2015 2:55 pm
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: If Statement
Are you attempting to make it work with a range of values? Because the way you have done it, won't work.
Code:
if((2047<SensorValue[Color]<=4095)) 

should be split up:
Code:
if((2047<SensorValue[Color]) && (SensorValue[Color] <=4095))

Do this for all of them.

= Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon Apr 13, 2015 10:57 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.