using Arduino to make a button - LED programme

// constants won't change. They're used here to
// set pin numbers:

int buttonPin = 3 ; // the number of the pushbutton pin
int ledPin = 11 ; // the number of the LED pin

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

// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT)

// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT)

while (True) {

// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin)

// check if the pushbutton is pressed.

// if it is, the buttonState is HIGH:

if (buttonState == HIGH) {

// turn LED on:
digitalWrite(ledPin, HIGH)
}

else {
// turn LED off:
digitalWrite(ledPin, LOW)

}
}

I am coming against :

error: expected constructor, destructor, or type conversion before '(' token pinMode(ledPin, OUTPUT) ^

Failed to compile file code.cpp

arduino build failed.

Please see the attachment for code details

I can't speak for anyone else, but that's totally indecipherable to me.

Please just put the code as text in a post, suitably tagged of course.

Your code has no setup() or loop() functions: Have a look at any of the File > Examples.

If you go File > New you'll get a template.

I'm confused: although I can't read the words in the screenshot, its structure looks like it has setup() and loop(), yet the code which you added to the opening post while I was posting #1, has no setup() or loop().

So why don't you, in a new post below this, post the code as is, in code tags for a fresh start...

This is the Whole code written by me

/*
Button

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

The circuit:

  • LED attached from pin 11 to ground
  • pushbutton attached to pin 3 from +5V
    */

// constants won't change. They're used here to
// set pin numbers:

int buttonPin = 3 ; // the number of the pushbutton pin

int ledPin = 11 ; // the number of the LED pin

// variables will change:

int buttonState = 0 ; // variable for reading the pushbutton status

// initialize the LED pin as an output:

pinMode(ledPin, OUTPUT)

// initialize the pushbutton pin as an input:

pinMode(buttonPin, INPUT)

while (True) {

// read the state of the pushbutton value:

buttonState = digitalRead(buttonPin)

// check if the pushbutton is pressed.

// if it is, the buttonState is HIGH:

if (buttonState == HIGH) {

// turn LED on:

digitalWrite(ledPin, HIGH)

}

else {

// turn LED off:

digitalWrite(ledPin, LOW)

}
}

It has no setup() or loop()...

Is it okay Now?

// constants won't change. They're used here to
// set pin numbers:

const int buttonPin = 3; // the number of the pushbutton pin

const int ledPin = 11; // the number of the LED pin

// variables will change:

int buttonState = 0; // variable for reading the pushbutton status

void setup() {

// initialize the LED pin as an output:

pinMode(ledPin, OUTPUT);

// initialize the pushbutton pin as an input:

pinMode(buttonPin, INPUT);
}

void loop() {

// read the state of the pushbutton value:

buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.

// if it is, the buttonState is HIGH:

if (buttonState == HIGH) {

// turn LED on:

digitalWrite(ledPin, HIGH);

} else {

// turn LED off:

digitalWrite(ledPin, LOW);

}
}

Is it okay Now?

Does it compile? If so does it do what you want?

Here it is in tags for readability:

// constants won't change. They're used here to
// set pin numbers:

const int buttonPin = 3;     // the number of the pushbutton pin

const int ledPin = 11;      // the number of the LED pin

// variables will change:

int buttonState = 0;         // variable for reading the pushbutton status

void setup() {

  // initialize the LED pin as an output:

  pinMode(ledPin, OUTPUT);

  // initialize the pushbutton pin as an input:

  pinMode(buttonPin, INPUT);
}

void loop() {

  // read the state of the pushbutton value:

  buttonState = digitalRead(buttonPin);



  // check if the pushbutton is pressed.

  // if it is, the buttonState is HIGH:

  if (buttonState == HIGH) {

    // turn LED on:

    digitalWrite(ledPin, HIGH);

  } else {

    // turn LED off:

    digitalWrite(ledPin, LOW);

  }
}