Created
November 12, 2013 04:28
-
-
Save dmccreary/7425484 to your computer and use it in GitHub Desktop.
Sample Arduino C program to fade and LED slowly on and off and control the delay time of ramp up, on, ramp down and off.
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
/* Based on the Arduino fader example | |
Dan McCreary | |
Nov. 2013 */ | |
int ledPin = 11; // LED connected from digital pin 11 to ground | |
int maxb = 155; // max brightness 0 to 255 | |
int inc = 1; // step increment value: typical values are from 1 to 10 | |
int slope = 20; // delay at each step in milliseconds - combine with inc to change speed transition | |
int delayOn = 1000; // how long to stay at max brightness in milliseconds | |
int delayOff = 2000; // how long to stay off in milliseconds | |
void setup() { | |
// nothing happens in setup | |
} | |
void loop() { | |
// fade in loop | |
for(int fadeValue = 0 ; fadeValue <= maxb; fadeValue +=inc) { | |
// sets the new value as we make the LED brighter (range from 0 to 255): | |
analogWrite(ledPin, fadeValue); | |
// wait see the dimming effect | |
delay(slope); | |
} ; | |
// how long to stay at full brightness | |
delay(delayOn); | |
// fade out loop | |
for(int fadeValue = maxb ; fadeValue >= 0; fadeValue -=inc) { | |
// sets the new value as we dim down | |
analogWrite(ledPin, fadeValue); | |
// wait a bit | |
delay(slope); | |
}; | |
// how long to stay at the off position | |
delay(delayOff); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there, great program but please could you tell me how to keep the (delay on) for 7 hours?
My dad is using this program for marine fish tank led's but having trouble with timings.please help.
Many thanks.