Hello, forum! I am looking for a way to change the forward/backward direction with a button on the controller (aka making the controller go backwards). I found directionType, but I’m not sure if it’s for just motors or drivetrains anymore Here’s my code!
/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: VEX */
/* Created: Thu Sep 26 2019 */
/* Description: Competition Template */
/* */
/*----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// Drivetrain drivetrain 1, 2, 3, 4
// Flippy motor 5
// Climber motor 6
// Controller1 controller
// ---- END VEXCODE CONFIGURED DEVICES ----
#include "vex.h"
#include "functions.h"
using namespace vex;
// A global instance of competition
competition Competition;
bool isBackwards = false;
bool buttonPressed = false; // no spamming hehe
bool buttonA = false;
/*---------------------------------------------------------------------------*/
/* Pre-Autonomous Functions */
/* */
/* You may want to perform some actions before the competition starts. */
/* Do them in the following function. You must return from this function */
/* or the autonomous and usercontrol tasks will not be started. This */
/* function is only called once after the V5 has been powered on and */
/* not every time that the robot is disabled. */
/*---------------------------------------------------------------------------*/
void pre_auton(void) {
// Initializing Robot Configuration. DO NOT REMOVE!
vexcodeInit();
// All activities that occur before the competition starts
// Example: clearing encoders, setting servo positions, ...
}
/*---------------------------------------------------------------------------*/
/* */
/* Autonomous Task */
/* */
/* This task is used to control your robot during the autonomous phase of */
/* a VEX Competition. */
/* */
/* You must modify the code to add your own robot specific commands here. */
/*---------------------------------------------------------------------------*/
void autonomous(void) {
doAuton(1); // choose which auton to run, 1 or 2 (check functions.cpp for the awesome code 👍)
}
/*---------------------------------------------------------------------------*/
/* */
/* User Control Task */
/* */
/* This task is used to control your robot during the user control phase of */
/* a VEX Competition. */
/* */
/* You must modify the code to add your own robot specific commands here. */
/*---------------------------------------------------------------------------*/
void usercontrol(void) {
while (1) {
buttonA = Controller1.ButtonA.pressing();
if (buttonA && !buttonPressed){
buttonPressed = true;
isBackwards = !isBackwards;
}
else if (!buttonA) buttonPressed = false;
if (isBackwards) {
Brain.Screen.print("!! NOW REVERSING !!");
// reverse direction
Drivetrain.directionType = reverse; // error
}
else {
Brain.Screen.print("!! NOW FORWARDING? !!");
// regular direction
Drivetrain.directionType = forward; // error
}
wait(20, msec);
}
}
//
// Main will set up the competition functions and callbacks.
//
int main() {
// Set up callbacks for autonomous and driver control periods.
Competition.autonomous(autonomous);
Competition.drivercontrol(usercontrol);
pre_auton();
while (true) {
wait(100, msec);
}
}
If it’s some really simple answer or something, I’m sorry for wasting your time. I tried looking at other posts to see an answer but I couldn’t figure anything out. This post is the closest I could get