Switched controlled Bi-color LED with TLC5947

A little background on my project. This is for a model railroad. The switch will be mounted on a control panel. When turned on or off, it will control a turnout on the tracks. The servo will move the turnout. The LED's will indicate if the turnout is open or closed.

My intent was that the first line moved the servo, second and third lines would turn the green or red LED's on or off. I've added my code revised with comments. When I move my switch between the on and off position, the servo moves as expected. The LED doesn't change. In fact both the red and green are lit. I'm not sure what I'm missing but did get it to compile without errors so headed in the right direction. I don't know Arduino coding to know where I'm going wrong and haven't been able to find what I'm looking for on either Google, Adafruit or Arduino.cc forums.

Again, thank you for your help.

I am trying to turn a red/green LED from red to green based on the position of a switch. The switch also controls the position of a servo. The switch is simple on/off. The LED is common anode. I have a UNO board and connected to it are the TLC5947 for the LEDs and a PCA9685 to control a servo. The switch works for servo control, the servo moves between to set points.

The connections are (dashes are for formatting)

UNO----PCA9685----TLC5947
A4------ SDA
A5------ SCL
2---------------------------------------------TO - SIDE OF SWITCH WITH RESISTOR AND THEN TO GROUND
5V-------Vcc-------------------------------TO + SIDE OF SWITCH
4---------------------------DIN
5---------------------------CLK
6---------------------------LAT
VIN------------------------V+
GRD---GRD------------GRD
-----------------------------0 channel to green leg of LED
------------------------------1 channel to red leg of LED
------------------------------common anode leg of LED to V+
----------0 channel to servo

#include <Wire.h>
#include <Adafruit_TLC5947.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

#define NUM_TLC5947 1

#define data   4
#define clock   5
#define latch   6
#define oe  -1  // set to -1 to not use the enable pin (its optional)

Adafruit_TLC5947 tlc = Adafruit_TLC5947(NUM_TLC5947, clock, data, latch);


int buttonPin0 = 2;   // Can add as many buttons as needed
int buttonState0 = 0;

void setup() {
  Serial.begin(9600);
  Serial.println("pca9685_TurnoutFinal!");
  pwm.begin();
  pwm.setPWMFreq(60);
  tlc.begin();
  delay(30);

  pinMode(buttonPin0, INPUT);

}

  void loop() {
  ///////////
  buttonState0 = digitalRead(buttonPin0);
  if (buttonState0 == HIGH) {               //swithc is on
    pwm.setPWM(0, 0, 370);                  //servo at channel 0 moves to position 370
    tlc.setPWM(0, 3000);  //LED at channel 0 turns on
    tlc.setPWM(1, 0);     //LED at channel 1 turns off
  }
  else  {                                    //switch is off
    pwm.setPWM(0, 0, 285);                   //servo at channel 0 moves to position 285
    tlc.setPWM(0, 0);      //LED at channel 0 turns off
    tlc.setPWM(1, 3000);   //LED at channel 1 turns on
  }
  }

I'm guessin that with the TLC5947, you're planning on a lot of turnout LEDs.
If it's only a single pair, you don't need the display driver, or if it's a 'few', you could use the I/O pins directly off the Arduino or MEGA with current limiting resistors

Tese may save you a bit of code

You are correct, there will be 10 turnouts, so 20 lights. I'm trying to get the basic code for the first turnout and then expand.

For 20 or more LEDs you’d get it all done with a MEGA by itself with some wires,
https://www.arduino.cc/en/Main/arduinoBoardMega2560/?setlang=en

OR as you planned, using an expander will certainly work.

To be really ‘neat’ and ‘simple’, you could use a simple 2-wire balanced SPI buss (for distance, and to minimise noise pickup), and something like a $0.20 74LS595 with 5V at each turnout... that would allow up to 8 LEDs at each node using basic SHIFTOUT commands.