expected unqualified-id before '?' token

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
}

Where?
Copy & paste the whole error message in code tags please.
I don't see anything terribly wrong in the code you've posted.

Sometimes variable are the same as key words.
Try changing LED and BUTTON to something a little different too, such as LED13 and BUTTON2

Always paste the complete error message for us to see.

.

Sorry forgot to post. That was what I was thinking too. There is nothing wrong right?

sketch_mar30a:40: error: expected unqualified-id before '?' token

 }?

  ^

exit status 1
expected unqualified-id before '?' token

I'd go with key word conflict then. Try changing the 2 names a little. Maybe current too.

There's a place to look those up in the IDE files somewhere.

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
    
 

}

Ok. I'd have to try at home and see what I get.

How does last get declared/changed?
if (last != currentIdk)

It gets declared in the function's it's parameters and in the loop function it's being given lastButton.

boolean currentIt
?
boolean currentIdt

Oops I didnt edit that. But that isnt causing the error.

Does someone maybe have a better debounce script? Just forninncommon.Sorry forbbad cimmunication typing from my phone with teamviewer.

Try this:

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
  }
  
}

Just read the switch every 50ms.

.

You have some unprintable ascii on your last line. Remove everything below digitalWrite and then add a new closing bracket.

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.

Already done in post 11

.

There are no question-marks in the posted code, so I'm guessing there's some kind of encoding problem.

RaytjeKn - how are you editing your code? Do you use the arduino IDE?

Thanks guys this fixed the problem!