Last active
May 14, 2018 23:05
-
-
Save jgillick/b2268084d656baf4ba0149e2f4c6a008 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
// THIS GIST HAS NOT BEEN COMPILED OR TESTED | |
/** | |
* Using the arduino-LEDFader library, this will fade an LED | |
* connected to pin 3 up, down, up and then hold that brightness | |
* for 10 minutes before fading the LED again. | |
* | |
* For a non-blocking version, see: https://gist.github.com/jgillick/f8fc7722f2c0d29d82b955d190b8b755 | |
*/ | |
#include <LEDFader.h> | |
#define HOLD_PWM 200 // The brightness to hold the LED at between breathing. | |
#define HOLD_TIME 600000 // How long to hold the LED between breathing. | |
#define FADE_TIME 3000 // The number of milliseconds each fade should take. | |
// Every time a fade completes, the program will move to the next step. | |
#define STEP_FADE_1 1 // fade all the way up | |
#define STEP_FADE_2 2 // fade all the way down | |
#define STEP_FADE_3 3 // fade up to HOLD_PWM brightness | |
#define STEP_HOLD 4 // hold this brightness for HOLD_TIME | |
LEDFader led = LEDFader(3); | |
uint8_t step = 0; | |
void setup() { | |
led.set_value(0); | |
} | |
void loop() { | |
led.update(); | |
// Transition to the next step when fading is done | |
if (led.is_fading() == false) { | |
step += 1; | |
switch(step) { | |
// Fade up | |
case STEP_FADE_1: | |
led.fade(255, FADE_TIME); | |
break; | |
// Fade down | |
case STEP_FADE_2: | |
led.fade(0, FADE_TIME); | |
break; | |
// Fade to hold brightness | |
case STEP_FADE_3: | |
led.fade(HOLD_PWM, FADE_TIME); | |
break; | |
// Hold it for HOLD_TIME milliseconds | |
case STEP_HOLD: | |
delay(HOLD_TIME); | |
break; | |
} | |
if (step >= STEP_HOLD) { | |
step = STEP_FADE_1; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment