Created
April 3, 2013 21:01
-
-
Save bakercp/5305264 to your computer and use it in GitHub Desktop.
"LED that I'm soldering to a protoshield to start off, fade up to full brightness for a period of about 45 seconds, begin fading to dark again and as it dims, to strobe."
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
const byte ledPin = 11; // pwm pin | |
boolean bIsGoingUp = true; | |
long fadeUpTime = 15000; // 45 * 1000 milliseconds | |
long fadeDownTime = 15000; // | |
long nextTransition = -1; | |
long strobeOnTime = 200; // the time the strobe effect will be on | |
long strobeOffTime = 1000; // the time the normal fade out will be on | |
boolean bIsStrobeOn = false; | |
long nextStrobeTransition = -1; | |
void setup() { | |
// nothing b/c we are using pwm out | |
Serial.begin(9600); | |
} | |
void loop() { | |
long now = millis(); | |
if(now > nextTransition) { | |
Serial.println("Transitioning."); | |
if(bIsGoingUp) { | |
nextTransition = now + fadeDownTime; | |
bIsGoingUp = false; | |
Serial.println("Going down!"); | |
} else { | |
nextTransition = now + fadeUpTime; | |
bIsGoingUp = true; | |
Serial.println("Going up!"); | |
} | |
} | |
long remainingTime = nextTransition - now; | |
Serial.println(remainingTime); | |
byte pwmValue = 0; | |
if(bIsGoingUp) { | |
pwmValue = map(remainingTime,fadeUpTime,0,0,255); | |
} else { | |
if(bIsStrobeOn) { | |
pwmValue = 255; // max | |
} else { | |
pwmValue = map(remainingTime,fadeUpTime,0,255,0); | |
} | |
if(now > nextStrobeTransition) { | |
if(bIsStrobeOn) { | |
nextStrobeTransition = now + strobeOffTime; | |
bIsStrobeOn = false; | |
} else { | |
nextStrobeTransition = now + strobeOnTime; | |
bIsStrobeOn = true; | |
} | |
} | |
} | |
analogWrite(ledPin,pwmValue); | |
delay(10); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment