Well I have the "exploring arduino" book and im working on the tutorial that allows to check for button states with Bouncing buttons. I followed the tutorials so far and have had minimal issues. This time, I have triple and quadruple checked the code and do not see the error. can someone double check it for me and present guidance.
Code is as follows:
const int LED=9; // The LED is connected to pin 9 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 current button state. boolean ledOn = false; // The present state of the LED (on/off) void setup() {
** pinMode (LED, OUTPUT); // Set the led pin as an output**
** pinMode (BUTTON, INPUT); // Set button as input (not required)** } /* * Debouncing Function * Pass it the previous button state, * and get back the current debounced buttion state. */ boolean debounce(boolean last) { boolean current = digitalRead(BUTTON); // Read the button state if (last != current) // If it's different... {
** delay(5); // 5ms wait**
** 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 button value**
** digitalWrite(LED, ledOn); // change the led state**
** }**
Error: A function definition is not allowed here before '{' token
Start at:-
boolean debounce(boolean last)
Count the number of { and the number of } until you get to the next function the loop one.
What do you see?
Is it correct?
AWOL!!!! Your AWESOME!!!! Thank you for the pick-me-up. Your response had me go back and relook at the entire code and I found the mistake. It was earlier in the code than I had anticipated. I just added the missin "}" and the compile did not yell at me. Thank you again AWOL XD
Ok Will do Grumpy Mike. Thank you guys, I apologize for posting before reading the rules. I just got over excited about solving this issue. I will behave accordingly from now on :%