Created
January 16, 2012 03:55
-
-
Save seeRead/1618975 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int pins[] = {11, 10, 9}; // R, G, B | |
int pinCnt = sizeof(pins) / sizeof(pins[0]); | |
String mode = "not test"; //set to test to debug | |
String mesg = "Pin "; | |
void ledDown(int pin, int lag){ | |
Serial.println(mesg + pin + " going down"); | |
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) { | |
analogWrite(pin, fadeValue); | |
delay(lag); | |
} | |
} | |
void ledUp(int pin, int lag){ | |
Serial.println(mesg + pin + " going up"); | |
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) { | |
analogWrite(pin, fadeValue); | |
delay(lag); | |
} | |
} | |
void setup() | |
{ | |
Serial.begin(115200); | |
if (mode == "test") { | |
for (int i=0; i < pinCnt; i++){ | |
pinMode(pins[i], OUTPUT); // set pin modes | |
} | |
} | |
} | |
void loop() | |
{ | |
if (mode == "test") { | |
for (int i=0; i < pinCnt; i++){ | |
for (int j=0; j < pinCnt; j++){ | |
if (i==j){ | |
digitalWrite(pins[j], HIGH); | |
Serial.println(mesg + pins[j] + " is on"); | |
} else { | |
digitalWrite(pins[j], LOW); | |
} | |
} | |
delay(500); | |
} | |
} else { // MAIN FUNCTION | |
for (int cycle=0; cycle < pinCnt; cycle++){ | |
ledUp(pins[cycle],30); | |
for (int i=0; i < pinCnt; i++){ | |
if (i!=cycle) | |
ledUp(pins[i],30); | |
} | |
for (int j=0; j < pinCnt; j++){ | |
if (j!=cycle) | |
ledDown(pins[j],30); | |
} | |
ledDown(pins[cycle],30); | |
}//end cycle | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment