View unanswered posts | View active topics It is currently Fri Feb 12, 2016 2:43 pm






Reply to topic  [ 3 posts ] 
Help on determining the cause for this non-functioning code 
Author Message
Rookie

Joined: Tue Nov 10, 2015 11:47 pm
Posts: 4
Post Help on determining the cause for this non-functioning code
Code:
while(SensorValue(IR) == 5)
   {
      motor[motorC] = 60;
      wait1Msec(2000);

      while(SensorValue(compass) < 205 && SensorValue(compass) > 235)
      {
         motor[motorB] = 30;
         motor[motorC] = -20;
      }
      motor[motorB] = 60;
      motor[motorC] = 60;
   }


Any help would be greatly appreciated thank you.


Wed Nov 11, 2015 12:18 am
Profile
Rookie

Joined: Tue Nov 10, 2015 11:53 pm
Posts: 2
Post Re: Help on determining the cause for this non-functioning c
Hello, bonglord.

I believe your problem is to do with this line of code: "while(SensorValue(compass) < 205 && SensorValue(compass) > 235)"
It's impossible for a number to be smaller than 205 and larger than 235 at the same time! Instead of using AND (&&), use OR (||), like so:

Code:
while(SensorValue(IR) == 5)
   {
      motor[motorC] = 60;
      wait1Msec(2000);

      while(SensorValue(compass) < 205 || SensorValue(compass) > 235)
      {
         motor[motorB] = 30;
         motor[motorC] = -20;
      }
      motor[motorB] = 60;
      motor[motorC] = 60;
   }


Hope that helps! :mrgreen:


Last edited by WhoIsThisForChan on Wed Nov 11, 2015 12:29 am, edited 2 times in total.



Wed Nov 11, 2015 12:23 am
Profile
Rookie

Joined: Tue Nov 10, 2015 11:47 pm
Posts: 4
Post Re: Help on determining the cause for this non-functioning c
Thanks for the help Chan.

I've implemented your changes and it's all working perfectly now :D


Wed Nov 11, 2015 12:29 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


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.