View Full Version : Programming a relay in C++
How do you do it? this is probably too general a question, but we just started using C++ for this build season, and we're pretty inexperienced. So we need to know how to properly initialize it, and just basically how to do it. sorry if that's not a good explanation, or if the subject is too broad.
Eric Finn
10-01-2009, 15:10
In this season's code, you would do the following:
Relay myRelay([slot],[chanel],kBothDirections); //initialize the relay in slot [slot], channel [channel], and allow it to move both directions
myRelay.Set(kForward); //turn the relay on in the forward direction
myRelay.Set(kOff); //turn the relay off
Value and Direction are enumerated in Relay.h in WPILib. Be aware that you cannot Set the Relay as kOn if you use kBothDirections as the third parameter to the Relay constructor.
If this isn't enough detail, just say so.
Since the enumerated members are in the Relay class, you need
myRelay.Set(Relay::kForward)
in order to set the proper scope for kForward.
Also, since the constuctor defaults to kBothDirections, you don't need to include that parameter.
So, to initialize a relay object called "r41" on DSC 4 relay channel 1 using the default mode (kBothDirections) and set it forward you'd use:
Relay r41(4,1);
r41.Set(Relay::kForward);
-Jeff
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.