View unanswered posts | View active topics It is currently Mon Sep 16, 2019 6:10 am






Reply to topic  [ 2 posts ] 
Need help with line-tracking code 
Author Message
Rookie

Joined: Wed Mar 04, 2015 10:33 pm
Posts: 1
Post Need help with line-tracking code
Hello, I have this problem with my code, I am not sure how to program it properly, therefore I am asking for help.
I'm making a marble sorter as a project in school, I'm at the last step of the marble sorter, sorting wood from plastic, however I am not sure how to code the line-tracker properly to work.
Currently it senses plastic marbles in the range of 100-300 and senses wood within the range of 301-1500.
It sensors the marbles just fine, however it will keep on running the code for wood and never stop.

What I want it to do is a marble comes down and then it runs the code for the specific marble, right now it will keep running the code for wood marble, even when there is no marble in front of the line-tracker. However if a plastic marble comes in front of it will run the code for plastic.

So overall my problem is just that it keeps on running, I want it to ONLY run when there is either a wood or plastic marble in front of the sensor.
I have posted my code below, thank you very much!

Code:
task Two()
{

  while(true)
  {
  if((SensorValue(lineTracker) < 300) && (SensorValue(lineTracker) > 100))
  {
    // sensor sees plastic:
        motor[leftMotor] = 0;
        wait1Msec(1000);
      motor[servoMotor]  = 127;
      wait1Msec(1000);
      motor[servoMotor] = 0;
    }
    // sensor sees wood:
    else((SensorValue(lineTracker) < 1500) && (SensorValue(lineTracker) > 301))
     {
       motor[leftMotor] = 30;
       wait1Msec(500);
       motor[leftMotor] = 0;
       wait1Msec(1500);
      motor[servoMotor]  = 127;
      wait1Msec(1000);
      motor[servoMotor] = 0;
      motor[leftMotor] = -30;
      wait1Msec(500);
      motor[leftMotor] = 0;
    }
  }
}


Wed Mar 04, 2015 10:44 pm
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post Re: Need help with line-tracking code
Try changing the else to an if.


Thu Mar 05, 2015 1:38 am
Profile
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:  
cron



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