Preseason Lesson3
It is expected that you completed Lesson 2 and have the code available.
The switches are consider digital inputs. Link to the DigitalInput documentation: DigitalInput
In Robot.h we will need an object/variable that is the switch. The class/object type is: frc::DigitialInput We will name the object: m_switchA In Robot.h, in the 'private:' section add the following line:
frc::DigitalInput m_switchA{0};
The '{0}' indicates the constructor will be called and '0' will be passed in for the channel parameter. NOTE: The switches on the test board are labelled with which channel they are on.
The frc::DigitalInput class contains the method 'Get()', which is what we will use to see if the switch is tripped. The method returns 'true' if the switch is tripped.
In Robot.cpp, you will modify the code in the Robot::OperatorControl() method. You will add more logic to the 'if's that are checking for the joystick position from lesson 2.
You will want to first test if the trigger is pressed. If it is pressed, then you will look at the position to see if the position to determine how to turn the motor. Here is the pseudo code (i.e. not actual code, replace the English words with actual code):
if (joystick trigger is pressed) { if ((joystick position is greater than 0.33) and (switch A is not tripped)) { spin motor forward 1/4 speed } else if ((joystick position is less than -0.33) and (switch B is no tripped)) { spin motor reverse 1/4 speed } else { stop motor } } else { stop motor }
After you have modified Robot.h and Robot.cpp, build the project.