DS Digital Input/Output

Recently my team went to a competition and I asked for help with out driver station. We had purchased a few Light Switches from the local hardware store and I had no idea how to wire them properly.

So he helped me wire them properly and connect them to DS 1 and 2 on the Driver Station and now I need to figure out how to code them.

My current code looks like this

bool switch1;
switch1 = m_ds->GetDigitalIn(1);
printf("Switch Value is: %d  ", switch1);

I never got to look at the code extensively during the competition but as far as I know it printed out all 0’s when the switch was in either position.

My next problem is we want to wire in a few LED’s to the DS so we know what is going on with the robot

m_ds->SetDigitalOut( 1,true);

I know how to wire the led’s but I need to know if this is the proper syntax to turn them on.

I’m not sure about the switch problem, cuz i was experiencing the same thing. However the if m_ds is a pointer refering to digital out on the ds, then that code should work. I didn’t have any problems with the LEDS.

A couple of suggestions:

1.Your printf is set to print an int, not a boolean. I don’t think there’s a flag for boolean, so you might want to change it to use two different printfs depending on the state of the variable

2.Check your switches with a multimeter and make sure current is actually getting through.

3.Check your digital outputs and see if you’re actually turning it on. If you are, chances are that you have reversed the polarity to the LED(LEDs are diodes, so they only work one direction)

My next best guess for C++ would be a “c” character flag? If im not mistaken it would print a t or a f then correct?

There seems to be a lot of confusion about what “wire them properly” really is. I think the software looks right, so maybe the hardware isn’t. What sort of light switches are you using? How are they wired?

I cant get my hands on the light switches right now but I know they have 3 wire leads. I remember him telling me something about “Getting around having to use a resistor” and Double Pole Double Throw

Thanks for all of the help so far!

printf("%i", true); will print 1
and printf("%i",false); will print0
you dont need a bool printf flag, or a if statement
just use the int flag (%i or %d)

It must be in the wiring in the switch then because I have tried that.

We experinced similar trouble. Wire a 1kOhm resistor between the power and signal wires on the switch. That should solve your problem.

I have a question on the jumpers also, my code looks like this:


enum{
   ARCADE_MODE = 1,
   ENABLE_AUTONOMOUS = 2,
   DRIVE = 3,
}jumpers;
....
....
void OperatorControl(void)
{
   while(1)
   {
      if(ds->GetDigtalIn(DRIVE)==1)
      {
         myRobot->TankDrive(-rightstick->GetY(), -leftstick->GetY());
      }
      else
      {
         myRobot->Drive(-leftstick->GetY(), -rightstick->GetX());
      }
   }
}

This isn’t really for competition reasons, except for merely trying to get the jumpers to work. When I don’t plug in the jumper it drives like how the else statement is written, but when I put a jumper on jumper pin#3 on the driver station it doesn’t go at all, and I’ve tried restarting the driver station and robot, and still same results, what is going on here? (I have counted the jumpers many times to make sure it was on the right one)

Explain which pin 3, there are a few of them, and the jumper goes from where to where exactly?

I’ve been using a really simple program to display my driver station inputs to the driver station LCD panel. C++ sources/project included:

http://www.virtualroadside.com/blog/index.php/2009/03/08/frc-driver-station-test-program/