Created
September 16, 2011 22:45
-
-
Save kevinmehall/1223343 to your computer and use it in GitHub Desktop.
Buttons / LEDs
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
void setup(){ | |
pinMode(6,INPUT); // Button | |
digitalWrite(6, HIGH); // Enable pull-up on pin 6 | |
pinMode(8,OUTPUT); // LED | |
} | |
int counter = 0; | |
int state = 0; | |
void loop(){ | |
int button = digitalRead(6); | |
if(button==0 && counter<255){ | |
counter = counter + 1; | |
}else if (counter > 0){ | |
counter = counter-1; | |
} | |
if (state){ | |
digitalWrite(8, HIGH); | |
state = 0; | |
}else{ | |
digitalWrite(8, LOW); | |
state = 1; | |
} | |
delay(counter); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment