Last active
August 29, 2015 14:07
-
-
Save reening/8cb7cfa60a4cf99230be to your computer and use it in GitHub Desktop.
Revisions
-
reening renamed this gist
Oct 2, 2014 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
reening revised this gist
Oct 2, 2014 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -9,6 +9,7 @@ /* Define the fade time in milliseconds */ #define FADE_TIME 60 #define GLOW_TIME (FADE_TIME * 3) /* Map the pins in order and calculate the pin count for later use */ int pins[] = { 12, 11, 10, 9, 8, 7, 6, 5 }; @@ -24,7 +25,7 @@ void setup() { /* Initialize all of the pins and set the fade time */ for(i=0; i<pin_count; ++i) { SoftPWMSet(pins[i], 0); SoftPWMSetFadeTime(pins[i], 0, GLOW_TIME); } } -
reening created this gist
Oct 2, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,51 @@ /* * Project week 5: Introduction to the Arduino * Night Rider-like fading LEDs * * Martijn Reening (s1523996) */ #include <SoftPWM.h> /* Define the fade time in milliseconds */ #define FADE_TIME 60 /* Map the pins in order and calculate the pin count for later use */ int pins[] = { 12, 11, 10, 9, 8, 7, 6, 5 }; int pin_count = sizeof(pins) / sizeof(int); /* Generic counter variable */ static volatile int i; void setup() { /* Initialize the SoftPWM library */ SoftPWMBegin(); /* Initialize all of the pins and set the fade time */ for(i=0; i<pin_count; ++i) { SoftPWMSet(pins[i], 0); SoftPWMSetFadeTime(pins[i], 0, FADE_TIME); } } void loop() { /* Fade in each LED in order of pins, and fade out when it's on */ for (i=0; i<pin_count; ++i) { SoftPWMSet(pins[i], 255); delay(FADE_TIME); SoftPWMSet(pins[i], 0); } /* Wait until the last LED is fully on */ delay(FADE_TIME); /* Same as above, but in reverse order */ for (--i; i>=0; --i) { SoftPWMSet(pins[i], 255); delay(FADE_TIME); SoftPWMSet(pins[i], 0); } /* Wait until the last LED is fully on */ delay(FADE_TIME); }