Created
January 13, 2012 21:47
-
-
Save seeRead/1608878 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 setup() | |
{ | |
Serial.begin(9600); | |
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 i=0; i < pinCnt; i++){ | |
ledUp(pins[i],30); | |
for (int j=0; j < pinCnt; j++){ | |
if (j!=i){ | |
ledUp(pins[j],30); | |
for (int k=0; k < pinCnt; k++){ | |
if (k!=j && k!=i){ | |
ledUp(pins[k],30); | |
ledDown(pins[k],30); | |
} | |
} | |
ledDown(pins[j],30); | |
} | |
} | |
ledDown(pins[i],30); | |
} | |
} | |
} | |
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment