Skip to content

Instantly share code, notes, and snippets.

@abcdmitry
Last active April 23, 2016 11:11
Show Gist options
  • Save abcdmitry/247ec4809f4865621266a2999ae79519 to your computer and use it in GitHub Desktop.
Save abcdmitry/247ec4809f4865621266a2999ae79519 to your computer and use it in GitHub Desktop.
int led = 7
byte brightness = 20
int detect = 9
int bright_max = 255
int bright_min = 20
const CLOSED = LOW;
const OPEN = HIGH;
pinMode(led, OUTPUT);
pinMode(detect, INPUT);
void setup(){
}
void loop() {
if (digitalRead(detect) == LOW && brightness > bright_min) {
brightness--;
analogWrite(led, brightness);
delay(10);
} else if (digitalRead(detect) == HIGH && brightness < bright_max) {
brightness++;
analogWrite(led, brightness);
delay(10);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment