Skip to content

Instantly share code, notes, and snippets.

@Youz13
Created January 21, 2018 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Youz13/3f3a10ba20cdeb7fb0054ce0dce8db24 to your computer and use it in GitHub Desktop.
Save Youz13/3f3a10ba20cdeb7fb0054ce0dce8db24 to your computer and use it in GitHub Desktop.
cyclecompt = 0;
while (cyclecompt < 220) {
analogWrite(led, brightness);
brightness = brightness + fadeAmount;
if ( brightness <= 10 ) { // On ending invert fadeAmount for next fade in
fadeAmount = -fadeAmount;
delay(1000);
}
if ( brightness >= 115 ) { // If led is full bright, invert fadeAmount to fade out
fadeAmount = -fadeAmount;
}
delay(delayM);
cyclecompt++;
if (digitalRead(mode) == HIGH) {
button_delay = 0;
while (digitalRead(mode) == HIGH) {
button_delay++;
delay(100);
if (button_delay > 10) { //no need to wait for user to release
digitalWrite(9, LOW);
digitalWrite(10, LOW);
EnD();
break;
}
}
if (button_delay < 10) { //short press
if (led == 9) {
for (int fadeValue = brightness ; fadeValue >= 0; fadeValue -= 5) {
analogWrite(9, fadeValue);
delay(30);
}
digitalWrite(9, LOW);
led = 10; button_delay = 0;
}
else {
for (int fadeValue = brightness ; fadeValue >= 0; fadeValue -= 5) {
analogWrite(10, fadeValue);
delay(30);
}
digitalWrite(10, LOW);
led = 9; button_delay = 0;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment