Skip to content

Instantly share code, notes, and snippets.

@dvtate
Last active June 6, 2016 00:09
Show Gist options
  • Save dvtate/5a100ece5b87df87092741d2b9241792 to your computer and use it in GitHub Desktop.
Save dvtate/5a100ece5b87df87092741d2b9241792 to your computer and use it in GitHub Desktop.
I wrote this function over a year ago, just backing up all the trash on my external HDD
inline void AnalogOutputTest(uint8_t startPin, uint8_t endPin, const int& timePerCycle, uint8_t incr = 5){
///checks pwm pins
if (startPin > endPin ) { // replace start & end pins
int cpStart = startPin,
cpEnd = endPin;
startPin=cpEnd;endPin=cpStart;
} else if (startPin == endPin) {
double delayTime = timePerCycle / ((startPin + 1 - endPin) * 51);
//fade the led in and out once
for (int fadeValue = 0; fadeValue <= 255; fadeValue += 5) {
analogWrite(startPin, fadeValue);
delay(delayTime);
}
for (int fadeValue = 255; fadeValue >= 0; fadeValue -= 5) {
analogWrite(startPin, fadeValue);
delay(delayTime);
}
} else {
double delayTime = timePerCycle / ((endPin + 1 - startPin) * 51);
// for each pin...
for (int currentpin = startPin + 1; currentpin <= endPin; currentpin++)
for (int fadeValue = 255; fadeValue >= 0; fadeValue -= 5) {//fade brightness
analogWrite(currentpin, fadeValue);
if (currentpin != endPin)
analogWrite(currentpin, 255 - fadeValue);
delay(delayTime);
}
}
}
void setup(){
//nothing to do here
}
void loop(){
AnalogOutputTest(2, 13, 1000);
/* replaces
// for each pin...
for (int currentpin = 2; currentpin != 13; currentpin++)
for (int lysstryke = 255; lysstryke >= 0; lysstryke -= 5) {//fade brightness
analogWrite(currentpin, lysstryke);
if (currentpin == 13) // end of row (start next cycle)
analogWrite(2, 255 - lysstryke);
else
analogWrite(currentpin+1, 255-lysstryke);
delay(10); // wait 10ms
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment