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