Skip to content

Instantly share code, notes, and snippets.

@kevinmehall
Created September 16, 2011 22:45
Show Gist options
  • Save kevinmehall/1223343 to your computer and use it in GitHub Desktop.
Save kevinmehall/1223343 to your computer and use it in GitHub Desktop.
Buttons / LEDs
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