View unanswered posts | View active topics It is currently Tue Sep 17, 2019 10:27 am






Reply to topic  [ 2 posts ] 
Code not working 
Author Message
Rookie

Joined: Thu Jan 28, 2016 9:58 am
Posts: 4
Post Code not working
I am trying to use a limit switch to count up to a set number and then run a motor for a set amount of time then stop after that I want it to keep counting until it reaches another amount and do the same thing as before.
Code:
#pragma config(Sensor, dgtl1,  limitSwitch,    sensorTouch)
#pragma config(Sensor, dgtl2,  limitSwitch2,   sensorTouch)
#pragma config(Motor,  port2,           motorOne,      tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port3,           motorTwo,      tmotorVex393_MC29, openLoop)
#pragma config(Motor,  port4,           moterThree,    tmotorVex393_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

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

   wait1Msec(2000);

   while (1==1)
   {
      waitUntil(SensorValue(limitSwitch) == 1);

      waitUntil (SensorValue(limitSwitch) == 0);

      w = w + 1;

      if (w == 5)

      motor[port2] = 100;

      wait1Msec(3000);
      motor[port2] = 0;

      if (w == 10)

      motor[port3] = 100;

      wait1Msec(3000);
      motor[port3] = 0;

      if (w == 15)

      motor[port4] = 100;

      wait1Msec(3000);
      motor[port4] = 0;
   }
}


Attachments:
File comment: This is the code
SourceFile002.c [931 Bytes]
Downloaded 139 times
Tue Apr 12, 2016 8:36 am
Profile
Expert

Joined: Thu Dec 01, 2011 12:07 am
Posts: 151
Post Re: Code not working
The code that runs when the if statement is true should be in braces after the if statement.

For example:
if (w == 5)
motor[port2] = 100;
wait1Msec(3000);
motor[port2] = 0;
becomes
if (w == 5)
{
motor[port2] = 100;
wait1Msec(3000);
motor[port2] = 0;
}

Your next challenge may be to only have the if statement execute once.


Tue Apr 12, 2016 11:43 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:  



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