10W RGB LED Motorcycle Application

So here's the situation:

I've got an older motorcycle (1980) and I'm reworking all of the lights on it. I've chosen to use 10W RGB leds (see below for specs) for the front turn signals (and aux high beams) and rear brake lights (and turn signals).

My original design (that I posted earlier) was going to use 74HC595's and NPN transistors. I was directed to use TPIC6A595 instead. I gave it a whirl and I tried leveraging ShiftPWM using PWM pins, but I found that the reaction speed to the directional signal or brakes was far too slow (approximately 2-5 seconds before the lights would react).

So the quest continues to find a suitable setup to control the lights on my bike.

The options that I've come up with in my head at this point are the following:

Jay

Link to the LED
http://www.ebay.com/itm/High-Power-Super-Bright-Integrated-RGB-LED-Light-Bulb-Beads-10W-Lamp-Bulb-1pc-/200885324100?_trksid=p2141725.m3641.l6368

Power: 10W
Voltage: Red 6-7V ; Green 9-12V ; Blue 9-12V
Life: <50,000 hours
Intensity Luminous: Red 620-625 LM, Green 520-525LM, Blue 460-465LM
Size: 2.6cm x 2cm/1.02'' x 0.79'' (approx)

This is the previous thread.
http://forum.arduino.cc/index.php?topic=401714.0

darktide:
I found that the reaction speed to the directional signal or brakes was far too slow (approximately 2-5 seconds before the lights would react).

Please post the code. There must be something wrong with it.
A 74HC595 should be lightning fast for that application.
Leo..

Post the schematic also. Could be floating control pins - like OE/ not tied low, or MR not tied high.
OE/ can also be driven with PWM pin for fading up & down.

but I found that the reaction speed to the directional signal or brakes was far too slow (approximately 2-5 seconds before the lights would react).

By guess is the miss use of the delay function.

I think that Mike is likely right.

So here is how this all plays out. Currently I haven't actually gotten the rear lights to function. The FastLED function is actually indicator lights for the instrument cluster of the bike (so I can avoid being that guy who has his blinker on for 5 minutes). I've been using those lights to gauge the reaction speed of the system. Any function that contains the Left or Right RGB functions adds considerable time to the reaction speed. If it just involves the FastLED light function, then it moves along at the appropriate speed.

// Start of Pololu Import
// Pololu must be included first
#include <PololuLedStrip.h>
// Create an ledStrip object and specify the pin it will use.
PololuLedStrip<3> ledStrip;

// Create a buffer for holding the colors (3 bytes per color).
#define LED_COUNT 60
rgb_color colors[LED_COUNT];
#include <FastLED.h>
#define NUM_LEDS 6
#define DATA_PIN 3
CRGB leds[NUM_LEDS];

// End of Pololu Import

// Start of ShiftPWM Import
// ShiftPWM requires that the pins be defined before the library included
const int ShiftPWM_latchPin = 11; // Used for the shift register communication
int ShiftPWM_clockPin = 10; // Used for the shift register communication
int ShiftPWM_dataPin = 5; // Used for the shift register communication
const bool ShiftPWM_invertOutputs = true;
const bool ShiftPWM_balanceLoad = false;

#include <CShiftPWM.h>
#include <ShiftPWM.h>

// Set the constants for using ShiftPWM
unsigned char maxBrightness = 255;
unsigned char pwmFrequency = 75;
int numRegisters = 2;

// End of ShiftPWM Import

// Pinout
int brakeInput = A4; // Tapped into at the rear brake light
int highBeamInput = A5; // Tapped into at the headlight
int neutralInput = A2; // Tapped into at the cluster
int leftTurnInput = A1; // Tapped into at the left handlebar
int rightTurnInput = A0; // Tapped into at the left handlebar
//int instrumentPanel = 3; // Output to the 6 LED cluster indicators
int leftHighBeam = 9; // Output to an NPN to trigger the left high beam
int rightHighBeam = 6; // Output to an NPN to trigger the right high beam
// End of Pinout

// Variables
int fadeAmount = 5; // Used for brake and turn signal pulsing
int count = 0; // Used for brake and turn signal pulsing
int brakeVal = 0; // Used in the detection of the brake lights
int highBeamVal = 0; // Used in the detection of the high beam
int neutralVal = 0; // Used in the detection of the neutral gear
int leftVal = 0; // Used in the detection of the left turn signal
int rightVal = 0; // Used in the detection of the right turn signal
int i = 1; // Used for the Rainbow function
int pwLimit = 150; // Used in the detection of the input signals
int brightness = 55; // Used in the pulse programs
int Stop = 0; // Used in the Brake Pulse program
int power = 0; // unsure

String Brakes = "Off";
String LeftTurn = "Off";
String RightTurn = "Off";
String Neutral = "Off";
String HighBeam = "Off";
// End of Variables

// method for setting the left rear turn signal
void leftRGB(String color)
{
  if (color == "Red")
  {
  ShiftPWM.SetRGB(3,0,0,0);
  ShiftPWM.SetRGB(4,0,255,0);
  }
    if (color == "Blue")
  {
  ShiftPWM.SetRGB(3,255,0,0);
  ShiftPWM.SetRGB(4,0,0,0);  
  }
    if (color == "Yellow")
  {
  ShiftPWM.SetRGB(3,0,0,0);
  ShiftPWM.SetRGB(4,191,255,0);
  }
    if (color == "White")
  {
  ShiftPWM.SetRGB(3,255,0,0);
  ShiftPWM.SetRGB(4,255,255,0);
  }
    if (color == "Green")
  {
  ShiftPWM.SetRGB(3,0,0,0);
  ShiftPWM.SetRGB(4,127,0,0);
  }
    if (color == "Off")
  {
  ShiftPWM.SetRGB(3,0,0,0);
  ShiftPWM.SetRGB(4,0,0,0);
  }
}
// End of LeftRGB

// method for setting the right rear turn signal
void rightRGB(String color)
{
    if (color == "Red")
  {
  ShiftPWM.SetRGB(2,0,0,255);
  }
    if (color == "Blue")
  {
  ShiftPWM.SetRGB(2,255,0,0);
  }
    if (color == "Yellow")
  {
  ShiftPWM.SetRGB(2,0,191,255);
  }
    if (color == "White")
  {
  ShiftPWM.SetRGB(2,255,255,255);
  }
    if (color == "Green")
  {
  ShiftPWM.SetRGB(2,0,127,0);
  }
  if (color == "Off")
  {
  ShiftPWM.SetRGB(2,0,0,0);
  }
}
// End of RightRGB  

// Converts a color from HSV to RGB.
// h is hue, as a number between 0 and 360.
// s is the saturation, as a number between 0 and 255.
// v is the value, as a number between 0 and 255.
rgb_color hsvToRgb(uint16_t h, uint8_t s, uint8_t v)
{
    uint8_t f = (h % 60) * 255 / 60;
    uint8_t p = (255 - s) * (uint16_t)v / 255;
    uint8_t q = (255 - f * (uint16_t)s / 255) * (uint16_t)v / 255;
    uint8_t t = (255 - (255 - f) * (uint16_t)s / 255) * (uint16_t)v / 255;
    uint8_t r = 0, g = 0, b = 0;
    switch((h / 60) % 6){
        case 0: r = v; g = t; b = p; break;
        case 1: r = q; g = v; b = p; break;
        case 2: r = p; g = v; b = t; break;
        case 3: r = p; g = q; b = v; break;
        case 4: r = t; g = p; b = v; break;
        case 5: r = v; g = p; b = q; break;
    }
    return (rgb_color){r, g, b};
}

void getValues()
{
 brakeVal = analogRead(brakeInput) ;
 highBeamVal = analogRead(highBeamInput);
 neutralVal = analogRead(neutralInput);
 leftVal = analogRead(leftTurnInput);
 rightVal = analogRead(rightTurnInput);
 
 if (brakeVal > pwLimit) {Brakes = "On";}
 if (brakeVal < pwLimit) {Brakes = "Off";}
 if (highBeamVal > pwLimit) {HighBeam = "On";}
 if (highBeamVal < pwLimit) {HighBeam = "Off";}
 if (neutralVal > pwLimit) {Neutral = "On";}
 if (neutralVal < pwLimit) {Neutral = "Off";}
 if (leftVal > pwLimit) {LeftTurn = "On";}
 if (leftVal < pwLimit) {LeftTurn = "Off";}
 if (rightVal > pwLimit) {RightTurn = "On";}
 if (rightVal < pwLimit) {RightTurn = "Off";}
 }
// End of getValues

void setup()
{
  pinMode(brakeInput, INPUT); // Brake
  pinMode(highBeamInput, INPUT); // Reverse
  pinMode(neutralInput, INPUT); // License
  pinMode(leftTurnInput, INPUT); // Left Turn
  pinMode(rightTurnInput, INPUT); // Right Turn
  pinMode(rightHighBeam, OUTPUT);
  pinMode(leftHighBeam, OUTPUT);

FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  leds[0] = CRGB(0,0,0);
  leds[1] = CRGB(0,0,0);
  leds[2] = CRGB(0,0,0);
  leds[3] = CRGB(0,0,0);
  leds[4] = CRGB(0,0,0);
  leds[5] = CRGB(0,0,0);
  FastLED.show();
delay(100);
  leftRGB("Red");
  rightRGB("Red");
  leds[0] = CRGB(0,255,0);
  FastLED.show();
delay(500);
  leftRGB("Yellow");
  rightRGB("Yellow");
  leds[1] = CRGB(0,255,0);
  FastLED.show();
delay(500);
  leftRGB("Blue");
  rightRGB("Blue");
  leds[2] = CRGB(0,255,0);
  FastLED.show();
delay(500);
  leftRGB("Green");
  rightRGB("Green");
  leds[5] = CRGB(0,255,0);
  FastLED.show();
delay(500);
  leftRGB("White");
  rightRGB("White");
  leds[4] = CRGB(0,255,0);
 FastLED.show();
delay(500);
  leds[3] = CRGB(0,255,0);
 FastLED.show();
 delay(500);
  leds[0] = CRGB(0,0,0);
  leds[1] = CRGB(0,0,0);
  leds[2] = CRGB(0,0,0);
  leds[3] = CRGB(0,0,0);
  leds[4] = CRGB(0,0,0);
  leds[5] = CRGB(0,0,0);
  FastLED.show();
 
}
// End Setup


void loop()
{
  
   // If a comparison evaluates true, then a zero will be returned. 
//If it is different, then a positive 1 or negative 1 will be returned. To coutner the possibility of a negative and positive one cancelling out, the absolute values have been used

getValues();

if (Neutral.compareTo("On")==0)
{
leds[4] = CRGB(255,0,0);
}
if (Neutral.compareTo("Off")==0)
{
leds[4] = CRGB(0,0,0);
} 
if (abs((LeftTurn.compareTo("On")) + abs(RightTurn.compareTo("Off")) + abs(Brakes.compareTo("On"))) == 0){
leftRGB("Yellow");
leds[2] = CRGB(191,255,0);
rightRGB("Red");
leds[0] = CRGB(0,255,0);
}
// functions truncated due to 9000char limit
FastLED.show();
}

I appreciate all of the assistance. Feel free to tell me that I'm stupid, I only ask that you give me some ideas on how to improve myself :slight_smile:

I don't have straight up schematics, I've attached the board layouts from DipTrace that I used to space everything out.

Jay

Jay, I can immediately see various parts that are inefficiently coded. For example use of Strings as Boolean variables and state/enum variables. These things don't matter much on a quad core 64 bit desktop CPU but..

Also when using the analog inputs as digital inputs, you can use digitalRead() and compare to HIGH and LOW.

And, expected, quite a few delay() calls there.

Your PCB layout pictures are very nice but don't help is understand the circuit. Please give us some schematics. Hand drawn on paper is fine.

Paul

Thanks Paul. I will work on the schematics but it may take me a day or two.

Obviously, I'm quite the amateur. The delay's are in the setup, what is the best way to have the program stop processing for a second during the start up?

I'll revamp the comparisons and leverage boolean values instead of string comparisons.
Jay

So this was the best I could come up with quickly.

The 12V rail is fed directly from the bike's battery line (fused), the 10W leds seem to deal with this just fine. The 5V rail is feed back a buck booster that maintains a steady 5V.

To recap, the pololu LEDs work fine. I use them to tell me how fast the system is responding. I still haven't gotten the rear LEDs to light using the TPIC6A595 setup. The front lights are setup a little different than I have setup in the schematic due to a wiring error. I'm in the process of fixing that issue but I'm trying to get this sorted out first.

I look forward to any assistance.

Jay

I think your main problem is the use of shiftPWM, this takes up a lot of processing time and this coupled with your very inefficient way the rest of the code is written is giving you the delay.

I understand the concept of using the shift register and latching to set the bit, but since the register is controlling each leg of my RGB LED, I need to have the red be at 255 and the green be at 191 in order to achieve the correct yellow. I'm not sure how I would go about doing that (hence the use of ShiftPWM). I don't want to ask for hand holding here, I want to know how to do these things, so if you can point me in the right direction for information I will go hunt the information down. Thanks for all the help each of you has provided so far.
Jay

As I said shiftPWM is very processor intensive. Do you need to change this colour? If not why not just use a different resistor value for each colour leg? Then you can just turn them on and off.

But first get rid of all those silly strings and string comparisons and just use Boolean variables.

I don't think Jay can achieve the required results by simply changing the series resistors. The leds need to be able to appear white. But perhaps only 4 brightness levels per channel are required, not 256. If ShiftPWM supports that it might use fewer resources.

But come on Jay let's see a version with no "String" variables. I don't see a single place in your code where they are needed.

I think this is just the wrong solution to controlling the LEDs.
These are 10W LEDs so you can't just put a current limiting resistor on them and expect them to work reliably. For LEDs of this power you need a constant current regulator.
If you require dimming then that constant current regulator has to be dimmable ( they are not all dimmable ).

Then you need something that can provide the PWM to dim them in hardware something like a PCA9685.

Here's the new code

#include <PololuLedStrip.h>
// Create an ledStrip object and specify the pin it will use.
PololuLedStrip<3> ledStrip;

// Create a buffer for holding the colors (3 bytes per color).
#define LED_COUNT 60
rgb_color colors[LED_COUNT];
#include <FastLED.h>
#define NUM_LEDS 6
#define DATA_PIN 3
CRGB leds[NUM_LEDS];

// End of Pololu Import


// ShiftPWM requires that the pins be defined before the library included
int latchPin = 11; // Used for the shift register communication
int clockPin = 10; // Used for the shift register communication
int dataPin = 5; // Used for the shift register communication

// Pinout
int brakeInput = A4; // Tapped into at the rear brake light
int highBeamInput = A5; // Tapped into at the headlight
int neutralInput = A2; // Tapped into at the cluster
int leftTurnInput = A1; // Tapped into at the left handlebar
int rightTurnInput = A0; // Tapped into at the left handlebar
int instrumentPanel = 3; // Output to the 6 LED cluster indicators
int leftHighBeam = 9; // Output to an NPN to trigger the left high beam
int rightHighBeam = 6; // Output to an NPN to trigger the right high beam
// End of Pinout

// Variables
int fadeAmount = 5; // Used for brake and turn signal pulsing
int count = 0; // Used for brake and turn signal pulsing
int brakeVal = 0; // Used in the detection of the brake lights
int highBeamVal = 0; // Used in the detection of the high beam
int neutralVal = 0; // Used in the detection of the neutral gear
int leftVal = 0; // Used in the detection of the left turn signal
int rightVal = 0; // Used in the detection of the right turn signal
int i = 1; // Used for the Rainbow function
int pwLimit = 150; // Used in the detection of the input signals
int brightness = 55; // Used in the pulse programs
int Stop = 0; // Used in the Brake Pulse program
int power = 0; // unsure
//holder for information you're going to pass to shifting function
byte data = 0; 
boolean Brakes = false;
boolean LeftTurn = false;
boolean RightTurn = false;
boolean Neutral = false;
boolean HighBeam = false;
// End of Variables

// method for setting the left rear turn signal
void leftRGB(String color)
{
  if (color == "Red")
  {
  //ShiftPWM.SetRGB(3,0,0,0);
  //ShiftPWM.SetRGB(4,0,255,0);
  leds[2] = CRGB(0,255,0);
  }
    if (color == "Blue")
  {
  //ShiftPWM.SetRGB(3,255,0,0);
  //ShiftPWM.SetRGB(4,0,0,0);  
  leds[2] = CRGB(0,0,255);
  }
    if (color == "Yellow")
  {
  //ShiftPWM.SetRGB(3,0,0,0);
  //ShiftPWM.SetRGB(4,191,255,0);
  leds[2] = CRGB(191,255,0);
  }
    if (color == "White")
  {
  //ShiftPWM.SetRGB(3,255,0,0);
  //ShiftPWM.SetRGB(4,255,255,0);
  leds[2] = CRGB(255,255,255);
  }
    if (color == "Green")
  {
  //ShiftPWM.SetRGB(3,0,0,0);
  //ShiftPWM.SetRGB(4,127,0,0);
  leds[2] = CRGB(255,0,0);
  }
    if (color == "Off")
  {
  //ShiftPWM.SetRGB(3,0,0,0);
  //ShiftPWM.SetRGB(4,0,0,0);
  leds[2] = CRGB(0,0,0);
  }
  FastLED.show();
}
// End of LeftRGB

// method for setting the right rear turn signal
void rightRGB(String color)
{
    if (color == "Red")
  {
  //ShiftPWM.SetRGB(2,0,0,255);
  leds[0] = CRGB(0,255,0);
  }
    if (color == "Blue")
  {
  //ShiftPWM.SetRGB(2,255,0,0);
  leds[0] = CRGB(0,0,255);
  }
    if (color == "Yellow")
  {
  //ShiftPWM.SetRGB(2,0,191,255);
  leds[0] = CRGB(191,255,0);
  }
    if (color == "White")
  {
  //ShiftPWM.SetRGB(2,255,255,255);
  leds[0] = CRGB(255,255,255);
  }
    if (color == "Green")
  {
  //ShiftPWM.SetRGB(2,0,127,0);
  leds[0] = CRGB(255,0,0);
  }
  if (color == "Off")
  {
  //ShiftPWM.SetRGB(2,0,0,0);
  leds[0] = CRGB(0,0,0);
  }
  FastLED.show();
}
// End of RightRGB  


// Method for setting the register values
void setRegisters()
{
 //ground latchPin and hold low for as long as you are transmitting
    digitalWrite(latchPin, 0);
    
      //return the latch pin high to signal chip that it 
    //no longer needs to listen for information
    digitalWrite(latchPin, 1);
    delay(100);
}


// End of setRegisters

// lightShiftPin
void lightShiftPinA(int p) {
  //defines a local variable
  int pin;

  //this is line uses a bitwise operator
  //shifting a bit left using << is the same
  //as multiplying the decimal number by two. 
  pin = 1<< p;

  //move 'em out
  shiftOut(dataPin, clockPin, pin);   

}
// End of lightShiftPinA

// ShiftOut Method
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
  // This shifts 8 bits out MSB first, 
  //on the rising edge of the clock,
  //clock idles low

  //internal function setup
  int i=0;
  int pinState;
  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, OUTPUT);

  //clear everything out just in case to
  //prepare shift register for bit shifting
  digitalWrite(myDataPin, 0);
  digitalWrite(myClockPin, 0);

  //for each bit in the byte myDataOut�
  //NOTICE THAT WE ARE COUNTING DOWN in our for loop
  //This means that %00000001 or "1" will go through such
  //that it will be pin Q0 that lights. 
  for (i=7; i>=0; i--)  {
    digitalWrite(myClockPin, 0);

    //if the value passed to myDataOut and a bitmask result 
    // true then... so if we are at i=6 and our value is
    // %11010100 it would the code compares it to %01000000 
    // and proceeds to set pinState to 1.
    if ( myDataOut & (1<<i) ) {
      pinState= 1;
    }
    else { 
      pinState= 0;
    }

    //Sets the pin to HIGH or LOW depending on pinState
    digitalWrite(myDataPin, pinState);
    //register shifts bits on upstroke of clock pin  
    digitalWrite(myClockPin, 1);
    //zero the data pin after shift to prevent bleed through
    digitalWrite(myDataPin, 0);
  }

  //stop shifting
  digitalWrite(myClockPin, 0);
}
// End ShiftOut Method


void getValues()
{
 brakeVal = analogRead(brakeInput) ;
 highBeamVal = analogRead(highBeamInput);
 neutralVal = analogRead(neutralInput);
 leftVal = analogRead(leftTurnInput);
 rightVal = analogRead(rightTurnInput);
 
 if (brakeVal > pwLimit) {Brakes = true;}
 if (brakeVal < pwLimit) {Brakes = false;}
 if (highBeamVal > pwLimit) {HighBeam = true;}
 if (highBeamVal < pwLimit) {HighBeam = false;}
 if (neutralVal > pwLimit) {Neutral = true;}
 if (neutralVal < pwLimit) {Neutral = false;}
 if (leftVal > pwLimit) {LeftTurn = true;}
 if (leftVal < pwLimit) {LeftTurn = false;}
 if (rightVal > pwLimit) {RightTurn = true;}
 if (rightVal < pwLimit) {RightTurn = false;}
 }
// End of getValues

void setup()
{
  pinMode(brakeInput, INPUT); // Brake
  pinMode(highBeamInput, INPUT); // Reverse
  pinMode(neutralInput, INPUT); // License
  pinMode(leftTurnInput, INPUT); // Left Turn
  pinMode(rightTurnInput, INPUT); // Right Turn
  pinMode(rightHighBeam, OUTPUT);
  pinMode(leftHighBeam, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  leds[0] = CRGB(0,0,0);
  leds[1] = CRGB(0,0,0);
  leds[2] = CRGB(0,0,0);
  leds[3] = CRGB(0,0,0);
  leds[4] = CRGB(0,0,0);
  leds[5] = CRGB(0,0,0);
  FastLED.show();
delay(100);
  leftRGB("Red");
  rightRGB("Red");
  FastLED.show();
delay(500);
  leftRGB("Yellow");
  rightRGB("Yellow");
  FastLED.show();
delay(500);
  leftRGB("Blue");
  rightRGB("Blue");
  FastLED.show();
delay(500);
  leftRGB("Green");
  rightRGB("Green");
  FastLED.show();
delay(500);
  leftRGB("White");
  rightRGB("White");
 FastLED.show();
delay(500);
 FastLED.show();
 delay(500);
  FastLED.show();
 
}
// End Setup


void loop()
{
  
getValues();

if (Neutral)
{
leds[4] = CRGB(255,0,0);
}
if (!(Neutral))
{
leds[4] = CRGB(0,0,0);
} 
if (HighBeam)
{
digitalWrite(leftHighBeam, HIGH);
digitalWrite(rightHighBeam, HIGH);
}
if (!(HighBeam))
{
digitalWrite(leftHighBeam, LOW);
digitalWrite(rightHighBeam, LOW);
}
if (LeftTurn && RightTurn && Brakes){
leftRGB("Yellow");
rightRGB("Red");
}
if (!(LeftTurn) && RightTurn && Brakes)
{
leftRGB("Red");
rightRGB("Yellow");
}
if (!(LeftTurn) && !(RightTurn) && Brakes)
{
leftRGB("Red");
rightRGB("Red");
}
if (!(LeftTurn) && !(RightTurn) && !(Brakes))
{
leftRGB("Green");
rightRGB("Green");
}
if (LeftTurn && !(RightTurn) && !(Brakes))
{
leftRGB("Yellow");
rightRGB("Green");

}
if (!(LeftTurn) && RightTurn && !(Brakes))
{
leftRGB("Green");
rightRGB("Yellow");
}
FastLED.show();
}

I tried to start working on the method for ShiftOut() instead of ShiftPWM().

After thinking about it, while I'd love the full spectrum of colors, I can definitely dim the green channel and be happy with that and just use ShiftOut() to take care of it. I won't use the fronts as aux high beams until I am able to design something like what Mike is suggesting.
Jay

Not sure if linking like this is discouraged:

This doesn't give the instructions on how to, it was another question. it looks like they were faced with the same situation. The advice given to them was to use Mosfets over NPNs and use Dimmable LED Drivers over Mosfets.

This looks to be a good DIY option from Instructables.

the downside I see to buying a premade option is that I will need 12 of them, and that jumps the price of this project up a considerable amount.

As always, I appreciate everyone's thoughts and advice.
Jay

This looks to be a good DIY option from Instructables.

You think? How are you going to dim that circuit?

Magic?
Yeah - I wasn't paying close enough attention.
Jay

Jay,

First, I feel obliged to say that the lights on your motorcycle are safety equipment, and that I advise against the modification of any safety equipment. Second, anything I say should be taken as hypothetical from here on out, and not as advice on modifying a vehicle.

The project which you propose is rather advanced. I looked over your code and can say that your micro-controller can not react to input if you tell it to go off and do a sequence of commands with delays in between. The delays have to go. When you check the status of an input over and over in a loop it is called polling, and that's not the most elegant way to handle outside input. Two concepts I think you will need to understand: multitasking, and interrupts. You will need multitasking to do more than one thing at a time. You use interrupts so that your program will react instantly to input like the brake being activated.

I looked around on this site and found a simple example of multitasking. It uses a timer to tell it when to do something at intervals as opposed to waiting for delays to expire. If you check out the attachInterrupt command you should be able to see how to implement an interrupt handler. You may have to share an interrupt pin with an or gate. Timers and interrupts are basically using subroutines with no parameters or return values.

I would suggest you copy the example in the link above and run it. Then remove the serial output code and replace it with something that blinks one LED. Take small steps until you are able to blink your LEDs exactly the way you want, and only then should you move on to add switches to your project. If you don't add anything to the loop, but instead add code only to the callbacks and interrupt handlers then I think you can get there. If things get too messy, start over.

I would also say that your code looks sloppy. You do not need two long routines for the two turn signals, you need one fairly short one. Yellow should not be 0,127,255, but rather YELLOW in your code - use constants with descriptive names. Don't type in lots of code and then test it; put in code in small increments and test it often - like eating an elephant, "small bites".

Plan to start over a few times. If you don't give up, then you won't fail.

-dm

DM
I appreciate the feedback, but I would like to come back around.
The concept of this isn't as intricate as it may seem. I've got something quite similar tied up into a license plate bracket that lights LEDs based off of the vehicle's electrical system. The primary difference (and why I needed help) was that running 4 individually addressable LEDs is quite different than running 4 10W RGB LEDs. This is where my focus was going and not on the code. The code's response time is rather nice as I time it against the indicator light panel I designed.

The reason for the sloppy code is mostly that I have had to move between several different libraries. This won't be the final code in my setup by a long shot. I do appreciate the tips and pointers as to where I should focus my work on cleaning it up though. The use of RGB(255,191,0) is that is the DOT specified value for an amber turn signal. I have not taken the time to compare it against how yellow looks.

On a side note, the brake and head lights are not hooked into this system so they will not fail if the arduino fails. The turn signals will, but hand signals will suffice (I will be alerted because my indicator panel will turn off).

I haven't given up yet and I won't stop until the project is complete

Jay