View Single Post
  #8   Spotlight this post!  
Unread 09-02-2015, 22:02
FleventyFive FleventyFive is offline
Registered User
FRC #4118
 
Join Date: Sep 2014
Location: Gainesville, FL
Posts: 23
FleventyFive is on a distinguished road
Re: Help with toggle-button

Here is some commented code that does what you want to get you started. If you are the only programmer on the team though, I agree you should try to find a mentor or another student who can help you out if you don't have much experience. Also, don't be afraid to read the errors and warnings eclipse is giving, often they make sense. Good luck!

Code:
#include "WPILib.h"

class Robot: public SampleRobot
{ //Define any variables like motors, sensors, or values here
	bool UseSecondMotor;
	Joystick stick;
	Talon m_motor1;
	Talon m_motor2;
public:
	Robot() : //Here is where you say what motors/sensors go into what ports on the RoboRio or the DriveStation computer, for example m_motor1 is in PWM port 1
		stick(0), //Change the 0 to the correct joystick, they are numbered from the order you plug them in
		m_motor1(1), //Change this to the correct PWM port where motor 1 is plugged in (ask electrical team)
	 	m_motor2(2) //Change this to the correct PWM port where motor 2 is plugged in (ask electrical team)
{
		//You can set the initial value of variables and do things like enable motor safety here
		UseSecondMotor = false;
}
	void Autonomous() //Where you will put the code that runs durring the Autonomous period of the match
	{
	}
	void OperatorControl()
	{
		//Put anything you want to happen once at the start of teleop here

		while (IsOperatorControl() && IsEnabled()) //This runs every 5 milliseconds in teleop, use it to read joystick values and write speeds to motors
		{
			UseSecondMotor = stick.GetRawButton(1); //Change the 1 to whatever button on the joystick you want to use to toggle (they are labled)
			if (UseSecondMotor) m_motor2.Set(stick.GetY());
			else m_motor1.Set(stick.GetY());
			Wait(0.005); //Don't remove this, this adds a delay so the computer doesn't crash and the motors have time to update
		}
	}
	void Test() //This is what runs when you click on test mode in the driver station, use to test motors, sensors, etc
	{
	}
};
START_ROBOT_CLASS(Robot);

Last edited by FleventyFive : 09-02-2015 at 22:07. Reason: More imformative
Reply With Quote