I have spent 2 hours already trying to debug my code but it still doesn’t work. The only not working part of the code is the wings and I can’t figure out why. The only difference between this version of code and the last is the addition of the intake control. Thanks for the help!
// Include the V5 Library
#include “vex.h”
// Allows for easier use of the VEX Library
using namespace vex;
//create motor objects for the left and right side of the drivetrain
const int wheelTravel = 275;
const int trackWidth = 370;
const int wheelBase = 330;
motor_group driveL(lf, lm, lb);
motor_group driveR(rf, rm, rb);
drivetrain Drivetrain(driveL, driveR, wheelTravel, trackWidth, wheelBase, mm);
void joystickControl() {
while (true) {
// Get the joystick values from the controller
int leftJoystick = Controller1.Axis3.position(percent);
int rightJoystick = Controller1.Axis2.position(percent);
// Set the motor speeds according to the joystick values
lf.spin(reverse, leftJoystick, percent);
lm.spin(forward, leftJoystick, percent);
lb.spin(reverse, leftJoystick, percent);
rf.spin(forward, rightJoystick, percent);
rm.spin(reverse, rightJoystick, percent);
rb.spin(forward, rightJoystick, percent);
wait(10, msec);
}
}
void Intake_Forward(){
Intake.setVelocity(100,percent);
Intake.spin(forward);
}
void Intake_Reverse(){
Intake.setVelocity(100,percent);
Intake.spin(reverse);
}
void Intake_Off(){
Intake.stop(vex::brakeType::coast);
}
void Intake_Control(){
bool intakeOn = false;
bool buttonL1Pressed = false;
bool buttonR1Pressed = false;
while(true){
if (Controller1.ButtonL1.pressing()) {
if (!buttonL1Pressed) {
buttonL1Pressed = true;
if (intakeOn) {
Intake_Off();
intakeOn = false;
}
else {
Intake_Forward();
intakeOn = true;
}
}
}
else {
buttonL1Pressed = false;
}
if (Controller1.ButtonR1.pressing()) {
if (!buttonR1Pressed) {
buttonR1Pressed = true;
if (intakeOn) {
Intake_Off();
intakeOn = false;
}
else {
Intake_Reverse();
intakeOn = true;
}
}
}
else {
buttonR1Pressed = false;
}
}
}
void Doinkage(){
while(true){
if(Controller1.ButtonY.pressing()){
if (!Doinker) {
Doinker.set(true);
}
else if (Doinker) {
Doinker.set(false);
}
wait(500,msec);}
}
}
void Wing_Control(){
bool Wings_state = false;
if (!Wings_state) {
Wings.set(true);
Wings_state = true;
}
else if (Wings_state) {
Wings.set(false);
Wings_state = false;
}
}
int main(){
thread mythread_I = thread(Intake_Control);
thread mythread_D = thread(Doinkage);
vex::thread t(joystickControl);
while(true) {
printf(“Loop RUN”);
if(Controller1.ButtonL2.pressing()){
Brain.Screen.print(“Test”);
printf(“Button Pressed!”);
Wing_Control();
waitUntil(!Controller1.ButtonL2.pressing()); // Wait until the button is released
wait(200,msec);
}
wait(20, msec); // This was outside the main function
}
return 0; // This should be the last statement in your main function
}