ROBOTC.net forumshttp://www.robotc.net/forums/ PLTW Vex Elevator codehttp://www.robotc.net/forums/viewtopic.php?f=69&t=14231 Page 1 of 1

 Author: HOMIEKALE [ Wed May 04, 2016 11:34 pm ] Post subject: PLTW Vex Elevator code Hi, in my engineering class in school I was instructed to design an elevator with three floors where when each bump switch was pressed, the elevator would move to that floor with its corresponding LED lighting up (floor 1: green, 2: yellow, 3: red). In my class, we haven't learned how to create a toggle out of a bump switch so I tried my best to create a piece of code that would move the elevator if the bump switch was held down. I'm not sure if this works yet because I simply typed it up in a notepad document at home because I don't have the Robot C software at home or my physical project with me. I was wondering if someone could take a look at what I wrote to:1. Tell me if it works or not regardless of how awkward the inputs might be2. Give me and pointers on how to improve or optimize it3. Show me a simple way to create a toggle on the switch so the if requirement isn't just if(SensorValue[bumpn]==1)btw I am using the PLTW software on robot C in Natural LanguageThank you to anyone who responds and can help me outcode:int bottom == .1 //check to make sure these values are correct for where you want the elevator to stop at, in inches//int middle == 2.5int top == 5void f1 ()void f2 ()void f3 ()void elevatorfcn ()void timeout ()cleartimer[T1]task main(){while(1==1){if(timer1[T1]<30000){elevatorfcn ();}else if(time1[T1]==30000){timeout ();}}}void f1 (){while(1==1){if(SensorValue[bump1]==1 && SensorValue[sonar]>.1){cleartimer[T1];turnLEDOn(G);startMotor(elevator, 63); //make sure to test if down or up is negative or positive on the power value//untilsonarlessthan(.2, sonar);stopMotor(elevator);}}}void f2 (){while(1==1){if(SensorValue[bump2]==1 && SensorValue[sonar]<2.5){cleartimer[T1]turnLEDOn(Y);startMotor(elevator, 63);untilsonargreaterthan(2.5, sonar);stopMotor(elevator);}else if(SensorValue[bump2]==1 && SensorValue[sonar]>2.5){cleartimer[T1];turnLEDOn(Y);startMotor(elevator, -63);untilsonarlessthan(2.6, sonar);stopMotor(elevator);}}}void f3 (){while(1==1);{if(SensorValue[bump3]==1 && SensorValue[sonar]<5){cleartimer[T1];turnLEDOn(R);startMotor(elevator, 63);untilSonargreaterthan(4.9, sonar);stopMotor(elevator);}}}void elevatorfcn (){while(1==1){f1 ();f2 ();f3 ();}}void timeout (){turnLEDOn(G);startMotor(elevator, -63)untilsonarlessthan(.2, sonar);stopMotor(elevator);}

 Page 1 of 1 All times are UTC - 5 hours [ DST ] Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Grouphttp://www.phpbb.com/