Hi All,
First post here.
I'm pretty new to Arduino, so happy to brand myself as an arduino noob.
I'm utilizing an Arduino Uno and PCA9685 servo controller to control Model Railway signals (both servo driven semaphore signals and LED searchlights) through JMRI (A Java-based DCC interface).
I’m trying to set up a common anode Red-Yellow-Green searchlight signal with a PCA9685 controlling the outputs. Simple, and nothing special or exciting.
I understand, that a standard LED needs to be connected to the PWM and GND pins on the controller – which when bread boarded, works great, no issues at all – LED turns on and off as expected
However how do I wire up the PCA to use a common anode LED?
I thought the correct way, was to have the common anode patched a (any) V+ pin, and each of the ‘colour’ wires (Red, yellow, green - which are on the cathodes of the LED) patched to the individual PWM pins for each output. Ie.
Outputs 0 & 1 are driving two servos connected to a semaphore signal.
Output 2 (Red indication): V+ pin, Red lead to PWM.
Output 3 (Yellow indication): Yellow lead to PWM
Output 4 (Green indication): Green lead to PWM
Is this correct?
For info, the sketch being used for this is below - based on the sketch provided via Little Wicket Railway on Youtube. It works fine for the servo's (though they could do with being slowed down alot - though again, that's beyond my understanding at the moment).
> #include <Wire.h>
>
> #include <Adafruit_PWMServoDriver.h>
>
> #include <CMRI.h>
>
> [#include](https://www.facebook.com/hashtag/include?__eep__=6&__cft__[0]=AZXpPnLFFVVqnvCcEWYLXHqcF2nXlLfAZY06Zj44EE3Oe_fHmHghfARKODtb0eGv5p6g4fjiH--Rm8t2js-Jgk2STcyIdew4EXGlangMTXbssL2eqexa-u5oZUDyWiB8azk&__tn__=R]-R) <Auto485.h>
>
> #define CMRI_ADDR 1
>
> #define DE_PIN 2
>
> [#define](https://www.facebook.com/hashtag/define?__eep__=6&__cft__[0]=AZXpPnLFFVVqnvCcEWYLXHqcF2nXlLfAZY06Zj44EE3Oe_fHmHghfARKODtb0eGv5p6g4fjiH--Rm8t2js-Jgk2STcyIdew4EXGlangMTXbssL2eqexa-u5oZUDyWiB8azk&__tn__=R]-R) numServos 5 //The number of servos connected
>
> Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); //setup the board address 0
>
> Auto485 bus(DE_PIN); // Arduino pin 2 -> MAX485 DE and RE pins
>
> CMRI cmri(CMRI_ADDR, 24, 48, bus);
>
> int Status[numServos]; //Create a table to hold the status of each turnout, signal, etc.
>
> int Throw[numServos]; //Create a table to hold the throw value for each servo
>
> int Close[numServos]; //Create a table to hold the close value for each servo
>
> void setup() {
>
> Serial.begin(9600);
>
> bus.begin(9600);
>
> pwm.begin();
>
> pwm.setPWMFreq(50); // This is the maximum PWM frequency
>
> //SET THE THROW AND CLOSE VALUES FOR EACH SERVO BASED ON THE CALIBRATION PROCESS
>
> //Servo connection 0 - Upper Quad Apamurra Junction Down Approach - Upper Arm
>
> Throw[0] = 1900;
>
> Close[0] = 1450;
>
> //Servo connection 1 - Upper Quad Apamurra Junction Down Approach - Lower Arm
>
> Throw[1] = 1350;
>
> Close[1] = 1940;
>
> //Servo connection 2 - Searchlight - Tailem Bend Up approach - RED
>
> Throw[2] = 4096;
>
> Close[2] = 0;
>
> //Servo connection 3 - Searchlight Tailem Bend Up Approach - YELLOW
>
> Throw[3] = 4096;
>
> Close[3] = 0;
>
> //Servo connection 4 - Searchlight Tailem Bend Up Approach - GREEN
>
> Throw[4] = 4096;
>
> Close[4] = 0;
>
> //Servo connection 5 - Searchlight Tailem Bend Down departure - RED
>
> Throw[5] = 4096;
>
> Close[5] = 0;
>
> }
>
> void loop(){
>
> cmri.process();
>
> for (int i = 0; i < numServos; i++) {
>
> Status[i] = (cmri.get_bit(i));
>
> if (Status[i] == 1){
>
> pwm.writeMicroseconds(i, Throw[i]);
>
> }
>
> else {
>
> pwm.writeMicroseconds(i, Close[i]);
>
> }
>
> }
>
> }
Any help would be greatly appreciated.
Thanks,
Pete