View Single Post
  #4   Spotlight this post!  
Unread 02-22-2016, 08:53 AM
pblankenbaker pblankenbaker is offline
Registered User
FRC #0868
 
Join Date: Feb 2012
Location: Carmel, IN, USA
Posts: 102
pblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of light
Re: Arduino Ethernet with roboRIO

I didn't actually write the code on the LED side (we have a lot of kids on the team and gave that task to a group of them).

However, I'm pretty sure the following code fragment demonstrates how to detect the current LED mode (4 choices: 0, 1, 2 and 3) and whether the mode has just changed:

Code:
// Change to the I/O pins you used
// to connect your Arduino to your roboRIO
int ledControl0 = 8;
int ledControl1 = 9;

// Current LED operating mode
int curMode = -1;

void setup() {
  // Set up I/O pins for LED control as inputs
  pinMode(ledControl0, INPUT);
  pinMode(ledControl1, INPUT);
}

void loop() {
  // Assume no LED mode change
  int modeChanged = 0;
  // Start with mode 0
  int mode = 0;
  if (digitalRead(ledControl0)) {
    // Control line 0 set, add 1 to mode (set bit 1 in mode)
    mode = mode + 1;
  }
  if (digitalRead(ledControl1)) {
    // Control line 1 set, add 2 to mode (set bit 2 in mode)
    mode = mode + 2;
  }

  // Check to see if mode changed since last check
  if (mode != curMode) {
    curMode = mode;
    modeChanged = 1;
  }

  // At this point, curMode will be a value of 0, 1, 2 or 3
  // and modeChanged will be 1 if the mode has changed from
  // last invocation or 0 if it is the same as last time 

  // Add your code below to set your LED display output
  // accordingly ...

}
Hope that helps.
Reply With Quote