Skip to content

Instantly share code, notes, and snippets.

@theotheo
Created November 9, 2014 15:37
Show Gist options
  • Save theotheo/5784f3d1796faf19d6a7 to your computer and use it in GitHub Desktop.
Save theotheo/5784f3d1796faf19d6a7 to your computer and use it in GitHub Desktop.
int switchPin = 6;
int ledPin = 4;
boolean lastButton = LOW;
boolean currentButton = LOW;
int ledLevel = 0;
void setup()
{
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
}
boolean debounce(boolean last)
{
boolean current = digitalRead(switchPin);
if (last != current)
{
delay(5);
current = digitalRead(switchPin);
}
return current;
}
void loop()
{
currentButton = debounce(lastButton);
if (lastButton == LOW && currentButton == HIGH)
{
ledLevel = ledLevel + 51;
}
lastButton = currentButton;
if (ledLevel > 255) ledLevel = 0;
analogWrite(ledPin, ledLevel);
delay (5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment