Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma config(Sensor, dgtl1, touchsense, sensorTouch)
- /*
- This program can can be used for NBT on the robots, it is very versitile
- and I hope we can make use of it
- By John (31/8/15 - 9/1/2015)
- */
- //bool to show if flywheel is activating
- bool flywheelrampCurrentlyActive = false;
- //bool to tell if flywheel is running
- bool FlyWheelRunning = false;
- //constant for motor off
- const int motorOff = 0;
- //bool to tell if stopswitch should be active
- bool stopSwitchState = false;
- //flywheel acceleration ramp func (void)
- void flywheelramp(int maxMotorSpeed = 127, int rampincreasePerLOOP = 1)
- {
- flywheelrampCurrentlyActive = true;
- //temporary storage for motor speed
- int tmpMotorSpeed = 10;
- //if not max speed then set speed to tmpMotorSpeed and add 1
- while(tmpMotorSpeed < maxMotorSpeed)
- {
- motor[port2] = tmpMotorSpeed;
- motor[port3] = tmpMotorSpeed;
- //long version of tmpMotorSpeed ++
- tmpMotorSpeed = tmpMotorSpeed + rampincreasePerLOOP;
- //give it a secound and dont hog the CPU
- wait1Msec(35);
- }
- flywheelrampCurrentlyActive = false;
- }
- //example of code in usage situation
- task main()
- {
- while(true)
- {
- /* AccelFlywheel and maxspeed
- -------------------------------------------------------------------------*/
- //Activation button for flywheel ramp and run
- if((vexRT[Btn7U] == 1) && FlyWheelRunning == false)
- {
- //clear encoders
- nMotorEncoder[port2] = 0;
- nMotorEncoder[port3] = 0;
- //runs flywheel ramp func
- flywheelramp(120,20);
- //set bool to true to show flywheel is running
- FlyWheelRunning = true;
- //tell the main while loop to start including stopSwitch in runs
- stopSwitchState = true;
- }
- /* StopSwitch Section
- -------------------------------------------------------------------------*/
- //if the stopswitch is needed to be used
- if(stopSwitchState == true)
- {
- //if the predesignated stopswitch is pressed
- if(Btn5D == true)
- {
- //set motors to the const MotorOff (or 0)
- motor[port2] = motorOff;
- motor[port3] = motorOff;
- //disable fly wheel currently spinning bool
- FlyWheelRunning = false;
- //bool to stop stopSwitch and 'disinclude' it in while runs
- stopSwitchState = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement