I'm getting this very weared error message, any help would be appreciated!
Code:
const int LED = 13; //The LED is connected to pin 10
const int BUTTON = 2; //The button is connected to pin 2
boolean lastButton = LOW; //Variable containing the previous button state
boolean currentButton = LOW; //Variable containing the current button state
boolean ledOn = false; //The present state of the LED
void setup()
{
pinMode (LED, OUTPUT); //Set the LED pin as an output
pinMode (BUTTON, INPUT); //Set button as an input
}
/*
* Debouncing Function
* Pass it the previous button state,
* and get back the current debounced button state.
*/
boolean debounce(boolean last)
{
boolean current = digitalRead(BUTTON); //Read the button state
if (last != current) //if it's different
{
delay(5); //wait 5ms
current = digitalRead(BUTTON); //read it again
return current; //return the current value
}
}
void loop()
{
currentButton = debounce(lastButton); //read debounced state
if (lastButton == LOW && currentButton == HIGH) //if it was pressed
{
ledOn = !ledOn; //toggle the LED value
}
lastButton = currentButton; //reset the button value
digitalWrite(LED, ledOn); //change the LED state
}
Nope did not work. This is what I changed it to. Is this what you were trying to say?
const int ledPin = 13; //The LED is connected to pin 10
const int buttonPin = 2; //The button is connected to pin 2
boolean lastButton = LOW; //Variable containing the previous button state
boolean currentButton = LOW; //Variable containing the current button state
boolean ledOn = false; //The present state of the LED
void setup()
{
pinMode (ledPin, OUTPUT); //Set the LED pin as an output
pinMode (buttonPin, INPUT); //Set button as an input
}
/*
* Debouncing Function
* Pass it the previous button state,
* and get back the current debounced button state.
*/
boolean debounce(boolean last)
{
boolean currentIt = digitalRead(buttonPin); //Read the button state
if (last != currentIdk) //if it's different
{
delay(5); //wait 5ms
currentIdk = digitalRead(buttonPin); //read it again
return currentIdk; //return the current value
}
}
void loop()
{
currentButton = debounce(lastButton); //read debounced state
if (lastButton == LOW && currentButton == HIGH) //if it was pressed
{
ledOn = !ledOn; //toggle the LED value
}
lastButton = currentButton; //reset the button value
digitalWrite(ledPin, ledOn); //change the LED state
}
const int ledPin = 13; //The LED is connected to pin 10
const int buttonPin = 2; //The button is connected to pin 2
boolean lastButton = LOW; //Variable containing the previous button state
boolean currentButton = LOW; //Variable containing the current button state
boolean ledOn = false; //The present state of the LED
void setup()
{
pinMode (ledPin, OUTPUT); //Set the LED pin as an output
pinMode (buttonPin, INPUT); //Set button as an input
}
/*
Debouncing Function
Pass it the previous button state,
and get back the current debounced button state.
*/
boolean debounce(boolean last)
{
boolean currentIdk = digitalRead(buttonPin); //Read the button state
if (last != currentIdk) //if it's different
{
delay(5); //wait 5ms
currentIdk = digitalRead(buttonPin); //read it again
return currentIdk; //return the current value
}
}
void loop()
{
currentButton = debounce(lastButton); //read debounced state
if (lastButton == LOW && currentButton == HIGH) //if it was pressed
{
ledOn = !ledOn; //toggle the LED value
lastButton = currentButton; //reset the button value
digitalWrite(ledPin, ledOn); //change the LED state
}
}
Did you copy and paste this code from somewhere? There's a weird character at the very end. Delete your whole last line and manually add the closing curly bracket back in.
saximus:
Did you copy and paste this code from somewhere? There's a weird character at the very end. Delete your whole last line and manually add the closing curly bracket back in.