/*
Arduino Tutorials
Episode 3
Switch4 Program (pwm)
Written by: Jeremy Blum
*/
int switchPin = 8;
int ledPin = 11;
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);
}
First of all, thanks for your time. The part of this code I dont really understand is the part of the beginning of the loop. currentButton calls for the debounce return, but what is (lastButton); doing? Video I am watching says he passes it to lastButton ,but I have no idea what that really means.
I realize this is on the lowend of programming, I promise I ordered an intro to programming book and plan to use it when it comes. In the mean time, can anyone help me understand this?
Much appreciated.