yes. here you go!
/*----------------------------------------------------------------------------*/
/* */
/* Module: main.cpp */
/* Author: VEX */
/* Created: Thu Sep 26 2019 */
/* Description: Competition Template */
/* Button Code: https://www.vexforum.com/t/walshbots-autonomous-feature-selector/51534 */
/*----------------------------------------------------------------------------*/
// ---- START VEXCODE CONFIGURED DEVICES ----
// Robot Configuration:
// [Name] [Type] [Port(s)]
// Controller1 controller
// FrontLeft motor 1
// BackLeft motor 2
// Arm motor 3
// LeftIntake motor 4
// RightIntake motor 7
// Lift motor 8
// FrontRight motor 9
// BackRight motor 10
// ---- END VEXCODE CONFIGURED DEVICES ----
#include "vex.h"
using namespace vex;
// A global instance of competition
competition Competition;
int autonomousSelection = -1;
typedef struct _button {
int xpos;
int ypos;
int width;
int height;
bool state;
vex::color offColor;
vex::color onColor;
const char *label;
} button;
button buttons[] = {
{ 30, 30, 60, 60, false, 0xE00000, 0x0000E0, "Color" },
{ 150, 30, 60, 60, false, 0x303030, 0xD0D0D0, "far" },
{ 270, 30, 60, 60, false, 0x303030, 0xF700FF, "Tower" },
{ 390, 30, 60, 60, false, 0x303030, 0xDDDD00, "3" },
{ 30, 150, 60, 60, false, 0x404040, 0xC0C0C0, "4" },
{ 150, 150, 60, 60, false, 0x404040, 0xC0C0C0, "5" },
{ 270, 150, 60, 60, false, 0x404040, 0xC0C0C0, "6" },
{ 390, 150, 60, 60, false, 0x404040, 0xC0C0C0, "7" }
};
void displayButtonControls( int index, bool pressed );
/*-----------------------------------------------------------------------------*/
/** @brief Check if touch is inside button */
/*-----------------------------------------------------------------------------*/
int
findButton( int16_t xpos, int16_t ypos ) {
int nButtons = sizeof(buttons) / sizeof(button);
for( int index=0;index < nButtons;index++) {
button *pButton = &buttons[ index ];
if( xpos < pButton->xpos || xpos > (pButton->xpos + pButton->width) )
continue;
if( ypos < pButton->ypos || ypos > (pButton->ypos + pButton->height) )
continue;
return(index);
}
return (-1);
}
/*-----------------------------------------------------------------------------*/
/** @brief Init button states */
/*-----------------------------------------------------------------------------*/
void
initButtons() {
int nButtons = sizeof(buttons) / sizeof(button);
for( int index=0;index < nButtons;index++) {
buttons[index].state = false;
}
}
/*-----------------------------------------------------------------------------*/
/** @brief Screen has been touched */
/*-----------------------------------------------------------------------------*/
void
userTouchCallbackPressed() {
int index;
int xpos = Brain.Screen.xPosition();
int ypos = Brain.Screen.yPosition();
if( (index = findButton( xpos, ypos )) >= 0 ) {
displayButtonControls( index, true );
}
}
/*-----------------------------------------------------------------------------*/
/** @brief Screen has been (un)touched */
/*-----------------------------------------------------------------------------*/
void
userTouchCallbackReleased() {
int index;
int xpos = Brain.Screen.xPosition();
int ypos = Brain.Screen.yPosition();
if( (index = findButton( xpos, ypos )) >= 0 ) {
// clear all buttons to false, ie. unselected
// initButtons();
// now set this one as true
if( buttons[index].state == true) {
buttons[index].state = false; }
else {
buttons[index].state = true;}
// save as auton selection
autonomousSelection = index;
displayButtonControls( index, false );
}
}
/*-----------------------------------------------------------------------------*/
/** @brief Draw all buttons */
/*-----------------------------------------------------------------------------*/
void
displayButtonControls( int index, bool pressed ) {
vex::color c;
Brain.Screen.setPenColor( vex::color(0xe0e0e0) );
for(int i=0;i<sizeof(buttons)/sizeof(button);i++) {
if( buttons[i].state )
c = buttons[i].onColor;
else
c = buttons[i].offColor;
Brain.Screen.setFillColor( c );
// button fill
if( i == index && pressed == true ) {
Brain.Screen.drawRectangle( buttons[i].xpos, buttons[i].ypos, buttons[i].width, buttons[i].height, c );
}
else
Brain.Screen.drawRectangle( buttons[i].xpos, buttons[i].ypos, buttons[i].width, buttons[i].height );
// outline
Brain.Screen.drawRectangle( buttons[i].xpos, buttons[i].ypos, buttons[i].width, buttons[i].height, vex::color::transparent );
// draw label
if( buttons[i].label != NULL )
Brain.Screen.printAt( buttons[i].xpos + 8, buttons[i].ypos + buttons[i].height - 8, buttons[i].label );
}
}
// define your global instances of motors and other devices here
/*---------------------------------------------------------------------------*/
/* 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) {}
/*---------------------------------------------------------------------------*/
/* */
/* 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) {
// User control code here, inside the loop
int temp = 0;
//hi
while (true) {
if (Controller1.ButtonX.pressing()&&temp<1)
{
autonomous();
FrontLeft.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
BackLeft.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
FrontRight.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
BackLeft.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
LeftIntake.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
RightIntake.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
FrontLeft.stop(brakeType::coast);
BackLeft.stop(brakeType::coast);
FrontRight.stop(brakeType::coast);
BackLeft.stop(brakeType::coast);
LeftIntake.stop(brakeType::coast);
RightIntake.stop(brakeType::coast);
}
// FrontLeft.spin(vex::directionType::rev, Controller1.Axis1.position() + Controller1.Axis3.position(), vex::velocityUnits::pct);
// BackLeft.spin(vex::directionType::fwd, Controller1.Axis1.position() + Controller1.Axis3.position(), vex::velocityUnits::pct);
// FrontRight.spin(vex::directionType::rev, Controller1.Axis1.position() - Controller1.Axis3.position() , vex::velocityUnits::pct);
// BackRight.spin(vex::directionType::fwd, Controller1.Axis1.position() - Controller1.Axis3.position() , vex::velocityUnits::pct);
// leftValue=Controller1.Axis3.value() + Controller1.Axis1.value();
// rightValue=Controller1.Axis3.value() - Controller1.Axis1.value();
FrontLeft.spin(vex::directionType::fwd, Controller1.Axis3.position(), vex::velocityUnits::pct);
BackLeft.spin(vex::directionType::fwd, Controller1.Axis3.position(), vex::velocityUnits::pct);
FrontRight.spin(vex::directionType::fwd, Controller1.Axis2.position() , vex::velocityUnits::pct);
BackRight.spin(vex::directionType::fwd, Controller1.Axis2.position(), vex::velocityUnits::pct);
//Tank drive ^^
if(Controller1.ButtonR2.pressing()) //intake sucks in
{
LeftIntake.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
RightIntake.spin(vex::directionType::fwd, 100, vex::velocityUnits::pct);
}
else if(Controller1.ButtonR1.pressing()) //intake blows out
{
LeftIntake.spin(vex::directionType::fwd, -100, vex::velocityUnits::pct);
RightIntake.spin(vex::directionType::fwd, -100, vex::velocityUnits::pct);
}
else
{
LeftIntake.stop(brakeType::coast);
RightIntake.stop(brakeType::coast);
}
if(Controller1.ButtonA.pressing()) //Spinner Slowly Sucks
{
LeftIntake.spin(vex::directionType::fwd, 80, vex::velocityUnits::pct);
RightIntake.spin(vex::directionType::fwd, 80, vex::velocityUnits::pct);
}
else if(Controller1.ButtonY.pressing()) //Spinner Slowly Blows
{
RightIntake.spin(vex::directionType::fwd, -80, vex::velocityUnits::pct);
LeftIntake.spin(vex::directionType::fwd, -80, vex::velocityUnits::pct);
}
if(Controller1.ButtonL2.pressing()) //Lift up
{
Lift.spin(vex::directionType::fwd, 70, vex::velocityUnits::pct);
}
else if(Controller1.ButtonL1.pressing()) //Lift down
{
Lift.spin(vex::directionType::fwd, -70, vex::velocityUnits::pct);
}
else
{
Lift.stop(brakeType::coast);
}
if(Controller1.ButtonUp.pressing()) //tray out
{
Arm.spin(vex::directionType::fwd, 40, vex::velocityUnits::pct);
}
else if(Controller1.ButtonDown.pressing())//tray in
{
Arm.spin(vex::directionType::fwd, -40, vex::velocityUnits::pct);
}
else
{
Arm.stop(brakeType::brake);
}
wait(20, msec); // Sleep the task for a short amount of time to
// prevent wasted resources.
}
}
//
// 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);
// Brain.Screen.print("ANDY JOW,ANDY JOW,ANDY JOW,ANDY JOW,ANDY JOW,ANDY JOW,ANDY JOW,ANDY JOW,ANDY JOW,ANDY JOW,ANDY JOW");
//Brain.Screen.printAt(50,150, "Tray:%f", Arm.rotation(rotationUnits::deg));
// Run the pre-autonomous function.
pre_auton();
Brain.Screen.pressed( userTouchCallbackPressed );
Brain.Screen.released( userTouchCallbackReleased );
// make nice background
Brain.Screen.setFillColor( vex::color(0x404040) );
Brain.Screen.setPenColor( vex::color(0x404040) );
Brain.Screen.drawRectangle( 0, 0, 480, 120 );
Brain.Screen.setFillColor( vex::color(0x808080) );
Brain.Screen.setPenColor( vex::color(0x808080) );
Brain.Screen.drawRectangle( 0, 120, 480, 120 );
// initial display
displayButtonControls( 0, false );
while(1) {
// Allow other tasks to run
if( !Competition.isEnabled() )
Brain.Screen.setFont(fontType::mono40);
Brain.Screen.setFillColor( vex::color(0xFFFFFF) );
Brain.Screen.setPenColor( vex::color(0xc11f27));
Brain.Screen.printAt( 0, 135, " THISTEAMGODMODE " );
this_thread::sleep_for(10);
}
// Prevent main from exiting with an infinite loop.
while (true) {
wait(100, msec);
}
}