Skip to content

Instantly share code, notes, and snippets.

@reening
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save reening/8cb7cfa60a4cf99230be to your computer and use it in GitHub Desktop.

Select an option

Save reening/8cb7cfa60a4cf99230be to your computer and use it in GitHub Desktop.

Revisions

  1. reening renamed this gist Oct 2, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. reening revised this gist Oct 2, 2014. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion nightrider.cpp
    Original 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, FADE_TIME);
    SoftPWMSetFadeTime(pins[i], 0, GLOW_TIME);
    }
    }

  3. reening created this gist Oct 2, 2014.
    51 changes: 51 additions & 0 deletions nightrider.cpp
    Original 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);
    }