View unanswered posts | View active topics It is currently Sun May 01, 2016 10:25 pm






Reply to topic  [ 2 posts ] 
Problems with coding a limit switch 
Author Message
Rookie

Joined: Thu Jan 28, 2016 9:58 am
Posts: 4
Post Problems with coding a limit switch
Hello I am in a high school engineering class we are using vex cortex parts and robotC for a project we are using. The problem we are having right now is that we are trying to use a limit switch to try and keep track of how many times it has been pressed down. The switch seems to count at a inconsistent rate and at this point we don't know what to do anymore. If there anything suggetions you have please let us know or if there is a better way to approch this all together that would help a lot. Thank you for your time.

Code:
 #pragma config(Sensor, dgtl1,  limitSwitch,    sensorTouch)
#pragma config(Motor,  port2,           motorOne,      tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
   int w = 0;
   motor[port2] = 0;

   wait1Msec(2000);

   while (1==1)
   {
      if (SensorValue(limitSwitch) == 1)
         w = w + 1;

      if (w > 5000)
         motor[port2] = 100;
   }
}


Tue Feb 23, 2016 9:46 am
Profile
Site Admin
Site Admin
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Post Re: Problems with coding a limit switch
This is a similar issue to the one I explained here: viewtopic.php?p=38220#p38220

= 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]


Wed Feb 24, 2016 3:20 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 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.