View unanswered posts | View active topics It is currently Mon Nov 11, 2019 9:35 pm






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

Joined: Tue May 19, 2015 9:59 am
Posts: 2
Post Vex Elevator Code not working
I have no idea why my code would work, so if you guys could fix and/or optimize it that would be great! The LEDs were the only thing working a bit ago, but now nothing works, and I have no idea why. What should happen is if you press a limit switch, it calculates the difference between which limit switch you pressed (1 2 or 3) and the current floor the elevator is on. It then should move the elevator cart accordingly, and also update the LEDs. If nothing is pressed for a while, it should go back down to the first floor. I would appreciate some help :)
Code:
#pragma config(Sensor, dgtl1,  LimitSwitch1,   sensorTouch)
#pragma config(Sensor, dgtl2,  LimitSwitch2,   sensorTouch)
#pragma config(Sensor, dgtl3,  LimitSwitch3,   sensorTouch)
#pragma config(Sensor, dgtl4,  SONAR,          sensorSONAR_inch)
#pragma config(Sensor, dgtl10, LED3,           sensorLEDtoVCC)
#pragma config(Sensor, dgtl11, LED2,           sensorLEDtoVCC)
#pragma config(Sensor, dgtl12, LED1,           sensorLEDtoVCC)
#pragma config(Motor,  port2,           mainmotor,     tmotorVex269_MC29, openLoop)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

task main()
{
int level;
int time;
int F;
int A;
int change;
level = 0;
time = 0;
startMotor(mainmotor,63);
while(SensorValue(SONAR)>2)
{
}
stopMotor(mainmotor);
turnLEDOn(LED3);
while(true)
{
   time = time + 1;
   if(SensorValue(LimitSwitch1)==1 || SensorValue(LimitSwitch2)==1 || SensorValue(LimitSwitch3)==1)
   {
      if(SensorValue(LimitSwitch1)==1)
      {
            F = 0;
      }
      if(SensorValue(LimitSwitch2)==1)
      {
         F = 1;
      }
      if(SensorValue(LimitSwitch3)==1)
      {
         F = 2;
      }
      time = 0;
      change = F - level;
      turnLEDOff(LED1);
      turnLEDOff(LED2);
      turnLEDOff(LED3);
      level = level + change;
      A = 0;
      if(change != 0)
      {
         A = change/abs(change);
      }
      startMotor(mainmotor,-63*A);
      while(SensorValue(SONAR) != 2*(F + 1))
      {
      }
      stopMotor(mainmotor);
      if(level==0)
      {
         turnLEDOn(LED3);
      }
      if(level==1)
      {
         turnLEDOn(LED2);
      }
      if(level==2)
      {
         turnLEDOn(LED1);
      }
   }
   if(time == 500 && SensorValue(SONAR)>2)
   {
      level = 0;
      startMotor(mainmotor,63);
      while(SensorValue(SONAR) > 3)
      {
      }
      stopMotor(mainmotor);
   }
}
}


Tue May 19, 2015 10:13 am
Profile
Rookie

Joined: Tue May 19, 2015 9:59 am
Posts: 2
Post Re: Vex Elevator Code not working
Nevermind, I think I got it to work even though I hardly did anything.... just need to adjust the SONAR so it works properly.


Tue May 19, 2015 4:16 pm
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.