I have an ongoing project i work on in my free time similar to this.
Here is a link to Tundra Geeks website where i have some videos, even though you can't see them too well.
http://tundrageeks.com/forum/showthread.php?t=2486&page=1
I think i have made some minor mods to the code since this, i have some functions in here that weren't even being called at this time.
The LED's are in each front door handle of my truck, each rear door handle and on the passenger and (soon to be) driver foot well.
/*
Program to do all kind of goofy crap with the LED's in my door handles
*/
const int fg = 4; // Assign each color for each handle ex: fg = Front Green and rr = Rear Red
const int fb = 3; // Interior light are tied to front door handles
const int fr = 2;
const int rg = 7;
const int rb = 6;
const int rr = 5;
const int colorIn = 15;
const boolean intlights = 48;
const boolean alarmIn = 52;
float colorValue = 0; //setting variables for later
int repeatCount = 1;
int alarmOffCount = 1;
int trueValue = 0;
int sampleTotal = 0;
long totalValue = 0;
int randomCheck;
void setup () {
pinMode (fg, OUTPUT); // Assign all pins
pinMode (fb, OUTPUT);
pinMode (fr, OUTPUT);
pinMode (rg, OUTPUT);
pinMode (rb, OUTPUT);
pinMode (rr, OUTPUT);
pinMode (colorIn, INPUT);
pinMode (intlights, INPUT);
pinMode (alarmIn, INPUT);
digitalWrite (intlights, HIGH); //Set inputs to maintain high
digitalWrite (alarmIn, HIGH);
digitalWrite (fg, LOW); // Turn all LED's off initially
digitalWrite (fb, LOW);
digitalWrite (fr, LOW);
digitalWrite (rg, LOW);
digitalWrite (rb, LOW);
digitalWrite (rr, LOW);
randomSeed(analogRead(0));
Serial.begin(9600);
}
void loop () {
/* Removed because no random patterns are needed
int totalPatterns = 8; //total numbers of patterns to pick from during random selection
int randomValue = random(1, totalPatterns + 1); //generate a random value for the next pattern to run
if (randomCheck == randomValue && randomCheck <= totalPatterns - 1){ //if the last pattern is the same as the one about to run go to next pattern
randomValue = randomValue + 1;
}
else if (randomCheck == randomValue && randomCheck == totalPatterns) { //if the last pattern was the last one in the series then go back one instead
randomValue = randomValue - 1;
}
randomCheck = randomValue; //set a varible to make sure the same pattern doesn't repeat
*/
if ( digitalRead (alarmIn) == HIGH && alarmOffCount == 0 ) {
alarmOffCount = 1;
ledFade (fr, fb, fg, rr, rg, rb, 35, .5, 5); // white fade when truck is unlocked
}
while (digitalRead (intlights) == LOW && digitalRead (alarmIn) == HIGH){ //code for interior lights to change colors selected by 5K pot
totalValue = 0; //reset variables at beginning of loop
trueValue = 0;
for (int i=1; i<=50 ; i++){ //take 50 readings from Analog Input pin
trueValue = analogRead(colorIn);
totalValue = trueValue + totalValue;
sampleTotal = i;
}
colorValue = totalValue/sampleTotal; //get average of 50 readings pulled in from loop
Serial.println(colorValue); // Print average color value to serial port
intLights (0, 175, 0, rr, 0, fr); // takes a value from the pot (0-1023) and uses that value to change the colors on the led
intLights (165, 345, rr, rb, fr, fb);
intLights (335, 515, rb, rg, fb, fg);
intLights (505, 685, rg, rr, fg, fr);
intLights (675, 855, 0, rb, 0, fb);
intLights (845, 1015, 0, rg, 0, fg);
}
while ( digitalRead (alarmIn) == LOW ) { // While viper is armed pin holds to low and the 4 color fade cycle repeats 100 times
alarmOffCount = 0;
for ( repeatCount=1 ; repeatCount<100 ; repeatCount++ ) {
ledFade (fr, 0, 0, rr, 0, 0, 50, 2, 5); //red fade
ledFade (0, fg, 0, 0, rg, 0, 30, .5, 5); //green fade
ledFade (0, 0, fb, 0, 0, rb, 30, 1, 5); //blue fade
ledFade (fr, fb, fg, rr, rg, rb, 30, .5, 5); // white fade
if ( digitalRead (alarmIn) == HIGH ) {
break;
}
}
}
//Notes to refer to when making calls
//ledStrobe (int f1, int f2, int f3, int r1, int r2, int r3, int strobeLow, int strobeHigh, float strobeStep)
//ledFade (int f1, int f2, int f3, int r1, int r2, int r3, int delayTime, float fadeIncrementOn, float fadeIncrementOff)
}
void intLights (int low, int high, int LEDlower1, int LEDraise1, int LEDlower2, int LEDraise2){ //takes the value from the pot and turns it into led values
if(colorValue == 0) {
digitalWrite(rr, LOW);
digitalWrite(fr, LOW);
digitalWrite(rg, LOW);
digitalWrite(fg, LOW);
digitalWrite(rb, LOW);
digitalWrite(fb, LOW);
}
else if(colorValue >1000){
digitalWrite(rr, HIGH);
digitalWrite(fr, HIGH);
digitalWrite(rg, HIGH);
digitalWrite(fg, HIGH);
digitalWrite(rb, HIGH);
digitalWrite(fb, HIGH);
}
else if (colorValue > low && colorValue < high){
int LED1 = map (colorValue, low, high, 255, 10);
int LED2 = map (colorValue, low, high, 10, 255);
int LED3 = map (colorValue, low, high, 255, 10);
int LED4 = map (colorValue, low, high, 10, 255);
analogWrite (LEDlower1, LED1);
analogWrite (LEDraise1, LED2);
analogWrite (LEDlower2, LED3);
analogWrite (LEDraise2, LED4);
}
}
void ledStrobe (int f1, int f2, int f3, int r1, int r2, int r3, int strobeLow, int strobeHigh, float strobeStep){
for (float strobeSpeed = strobeLow; strobeSpeed <=strobeHigh; strobeSpeed +=strobeStep){ //shift pf and df from flash speed at strobeLow to flash speed at strobeHigh
digitalWrite (f1, HIGH);
digitalWrite (f2, HIGH);
digitalWrite (f3, HIGH);
delay(strobeSpeed);
digitalWrite (f1, LOW);
digitalWrite (f2, LOW);
digitalWrite (f3, LOW);
delay(strobeSpeed);
}
for (float strobeSpeed = strobeHigh; strobeSpeed >=strobeLow; strobeSpeed -=strobeStep){ //shift pf and df from flash speed at strobeHigh to flash speed at strobeLow
digitalWrite (f1, HIGH);
digitalWrite (f2, HIGH);
digitalWrite (f3, HIGH);
delay(strobeSpeed);
digitalWrite (f1, LOW);
digitalWrite (f2, LOW);
digitalWrite (f3, LOW);
delay(strobeSpeed);
}
for (float strobeSpeed = strobeLow; strobeSpeed <=strobeHigh; strobeSpeed +=strobeStep){//shift pr and dr from flash speed at strobeLow to flash speed at strobeHigh
digitalWrite (r1, HIGH);
digitalWrite (r2, HIGH);
digitalWrite (r3, HIGH);
delay(strobeSpeed);
digitalWrite (r1, LOW);
digitalWrite (r2, LOW);
digitalWrite (r3, LOW);
delay(strobeSpeed);
}
for (float strobeSpeed = strobeHigh; strobeSpeed >=strobeLow; strobeSpeed -=strobeStep){//shift pr and dr from flash speed at strobeHigh to flash speed at strobeLow
digitalWrite (r1, HIGH);
digitalWrite (r2, HIGH);
digitalWrite (r3, HIGH);
delay(strobeSpeed);
digitalWrite (r1, LOW);
digitalWrite (r2, LOW);
digitalWrite (r3, LOW);
delay(strobeSpeed);
}
}
void ledFade (int f1, int f2, int f3, int r1, int r2, int r3, int delayTime, float fadeIncrementOn, float fadeIncrementOff){
for (float fadeValue = 0; fadeValue <=255 ; fadeValue +=fadeIncrementOn) { //fade door led's to on
analogWrite (f1, fadeValue);
analogWrite (f2, fadeValue);
analogWrite (f3, fadeValue);
analogWrite (r1, fadeValue);
analogWrite (r2, fadeValue);
analogWrite (r3, fadeValue);
delay(delayTime);
if ( digitalRead (alarmIn) == HIGH ){ //check to see if alarm is still armed
digitalWrite (fg, LOW); // Turn all LED's off
digitalWrite (fb, LOW);
digitalWrite (fr, LOW);
digitalWrite (rg, LOW);
digitalWrite (rb, LOW);
digitalWrite (rr, LOW);
repeatCount=1;
loop ();
}
}
for (float fadeValue = 255; fadeValue >=0 ; fadeValue -=fadeIncrementOff) { //fade door led's to off
analogWrite (f1, fadeValue);
analogWrite (f2, fadeValue);
analogWrite (f3, fadeValue);
analogWrite (r1, fadeValue);
analogWrite (r2, fadeValue);
analogWrite (r3, fadeValue);
delay(delayTime);
if ( digitalRead (alarmIn) == HIGH ){ //check to see if alarm is still armed
digitalWrite (fg, LOW); // Turn all LED's off
digitalWrite (fb, LOW);
digitalWrite (fr, LOW);
digitalWrite (rg, LOW);
digitalWrite (rb, LOW);
digitalWrite (rr, LOW);
repeatCount=1;
loop ();
}
}
digitalWrite (fg, LOW); // Turn all LED's off
digitalWrite (fb, LOW);
digitalWrite (fr, LOW);
digitalWrite (rg, LOW);
digitalWrite (rb, LOW);
digitalWrite (rr, LOW);
if ( digitalRead (alarmIn) == HIGH ){ //check to see if alarm is still armed
repeatCount=1;
loop ();
}
delay(1000);
if ( digitalRead (alarmIn) == HIGH ){//check to see if alarm is still armed
repeatCount=1;
loop ();
}
}