Last active
August 29, 2015 14:14
-
-
Save houhr/9160a414097347b6ec21 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
int led = 9; // the pin that the LED is attached to | |
int switch1 = 8; // the pin that switch 1 is attached to | |
int switch2 = 7; // the pin that switch 2 is attached to | |
boolean state1 = false; | |
boolean state2 = false; | |
int brightness = 0; // how bright the LED is | |
int fadeAmount = 5; // how many points to fade the LED by | |
void setup() { | |
pinMode(led, OUTPUT); | |
pinMode(state1, INPUT); | |
pinMode(state2, INPUT); | |
} | |
void loop() { | |
state1 = digitalRead(switch1); | |
state2 = digitalRead(switch2); | |
delay(1); | |
// Neither of switchers is closed | |
if (state1 == false && state2 == false) { | |
analogWrite(led, brightness); | |
brightness = brightness + fadeAmount; | |
if (brightness == 0 || brightness == 255) { | |
fadeAmount = -fadeAmount ; | |
} | |
delay(30); | |
} else { | |
// Switch 1 closed, the LED should be off. | |
if (state1 == true) { | |
digitalWrite(led, LOW); | |
// Switch 2 closed, the LED should be on at some intermediate brightness. | |
} else if (state2 == true) { | |
analogWrite(led, brightness); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment