Code:
#include "WPILib.h"
class RobotDemo : public SimpleRobot
{
RobotDrive myRobot;
Joystick stick;
// This declares the Relay
Relay Elevator;
public:
RobotDemo(void):
myRobot(1, 2),
stick(1),
// This sets up the Relay
Elevator(3)
{
myRobot.SetExpiration(0.1);
}
void Autonomous(void)
{
myRobot.SetSafetyEnabled(false);
myRobot.Drive(0.5, 0.0);
Wait(2.0);
myRobot.Drive(0.0, 0.0);
}
void OperatorControl(void)
{
myRobot.SetSafetyEnabled(true);
while (IsOperatorControl())
{
myRobot.ArcadeDrive(stick);
// This sets the relay
// if stick (USB 1), Trigger (Button 1) == pressed
if(stick.GetRawButton(1) == true)
// set Elevator (PWM 3) to forward
Elevator.Set(Relay::kForward);
else
// if stick (USB 1), Button 2 == pressed
if(stick.GetRawButton(2) == true)
// set Elevator (PWM 3) Reverse
Elevator.Set(Relay::kReverse);
else
// if stick (USB 1), Button 3 == pressed
if(stick.GetRawButton(3) == true)
// set Elevator (PWM 3) to Off
Elevator.Set(Relay::kOff);
Wait(0.005);
}
}
};
START_ROBOT_CLASS(RobotDemo);
This uses the Relay on PWM 3 and triggered by Buttons 1, 2, and 3 to run Forward, Reverse, and Off (respectively).
This is the Simple Robot code just modified to have a Relay too.