Hi I built the Vex robotics Protobot using the cortex. I have the arm programmed to move up and down with buttons and the driving and the front wheels all programmed with the Joystick. But I have limit switches to limit the arm so it doesn’t go to far. How do I program the limit switches to work with the Joystick code so it the arm hits the limit switch it goes back and stops so I can try again? I have attached the code.
#pragma config(Sensor, dgtl1, limitswitch1, sensorTouch)
#pragma config(Sensor, dgtl2, limitswitch2, sensorTouch)
#pragma config(Motor, port3, rightmotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port4, Lift, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port6, leftmotor, tmotorVex393_MC29, openLoop)
#pragma config(Motor, port7, Grab, tmotorVex393_MC29, openLoop)
//!!Code automatically generated by ‘ROBOTC’ configuration wizard !!//
/*
Project Title: PROTOBOT
Team Members: John
Date:
Section:
Task Description: PROTOBOT
Pseudocode:
*/
task main()
{ //Program begins, insert code within curly braces
while (true)
{
motor(leftmotor) = vexRT[Ch3];
motor(rightmotor) = vexRT[Ch2];
if (vexRT [Btn5D] ==1)
stopAllTasks();
if (vexRT [Btn6D] ==1)
stopAllTasks();
if (vexRT [Btn6U] ==1)
stopMotor(Lift);
if (vexRT [Btn5U] ==1)
stopMotor(Grab);
if (vexRT [Btn7U] ==1)
motor(Grab) = 100;
if (vexRT [Btn7D] ==1)
motor(Grab) = -100;
if (vexRT [Btn8U] ==1)
{
motor[Lift] = 140;
}
else if (vexRT [Btn8D] ==1)
{
motor[Lift] = -140;
}
else
{
motor[Lift] = 0; //If no button is pressed, stop motor
}
}
}