expected '}' at end of input

I know that it sound stupid but I tried to put the ‘}’ at the end of the input and it still show me that error. Could anyone help?

here is the full error message:

expected ‘}’ at end of input

}

^

Button.ino (1.48 KB)

This is why it helps to put the braces on their own separate lines so that you can easily see when they are missing their mating braces.

try it you will find it.

I will try.

Thaks :slight_smile:

Hutkikz:
This is why it helps to put the braces on their own separate lines so that you can easily see when they are missing their mating braces.

try it you will find it.

I tried it, and it might be becaus im stupid put there seems to be all there. Do you think it could be becaus there placement is rong. Im sorry, i'm used to KOP program.

no , one is missing it's mate. click tools > auto format
they each should line up vertically with it's mate.

Alternitave click on the opening brace and its matching closing mate will be highlighted.
You can then see if the closing brace matches where you think it is.

After an autoformat, your code is (I've removed the initial comments)

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
const int stopPin = 4;

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int stopState = 0;


void setup()
{
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  pinMode(stopPin, INPUT);
}

void loop()
{
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  stopState = digitalRead(stopPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH)
  {
    // turn LED on:
    noInterrupts();

    digitalWrite(ledPin, HIGH);
    delay(1000);
  } if (stopState == HIGH)
  {
    interrupts();
  }

  else
  {
    digitalWrite(ledPin, LOW);
  }

Do you notice a missing } ?

And the below part of above does not improve readability

 } if (stopState == HIGH)

It does not affect the code but it would be a lot more readable if you put the if on a new line.

You need one more } at the very end to complete the loop(){…

If you click on a parenthesis in the ide, it highlights the matching one - very useful in finding mismatched/missing parentheses. Try it.

I’d tidy it all up like this:

/*
  Button

  Turns on and off a light emitting diode(LED) connected to digital
  pin 13, when pressing a pushbutton attached to pin 2.


  The circuit:
   LED attached from pin 13 to ground
   pushbutton attached to pin 2 from +5V
   10K resistor attached to pin 2 from ground

   Note: on most Arduinos there is already an LED on the board
  attached to pin 13.


  created 2005
  by DojoDave <http://www.0j0.org>
  modified 30 Aug 2011
  by Tom Igoe

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Button
*/

// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
const int stopPin = 4;

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int stopState = 0;


void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
  pinMode(stopPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  stopState = digitalRead(stopPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  
  if (buttonState == HIGH) {
    // turn LED on:
    noInterrupts();

    digitalWrite(ledPin, HIGH);
    delay(1000);
  }

  if (stopState == HIGH) {
    interrupts();
  }

  else {
    digitalWrite(ledPin, LOW);
  }

}

Whether it does what you want is , of course, another matter

Allan

Thanks guys!!!!!