Error with code from Arduino starter KIT

Hellou.

I was practicing arduino, and wiring, and in getting started with arduino i was testing few things with first exc. with LEDs So, i have a error:

ketch_aug08a.ino:5:1: error: expected ',' or ';' before 'int'
sketch_aug08a.ino: In function 'void loop()':
sketch_aug08a.ino:18:5: error: 'state' was not declared in this scope
sketch_aug08a.ino:20:5: error: 'state' was not declared in this scope
sketch_aug08a.ino:21:24: error: too many arguments to function 'int digitalRead(uint8_t)'

And i was following the book.

Code is :

const int LED = 13;
const int BUTTON = 7;
int val = 0;
int state = 0;

void setup() 
{

pinMode(LED, OUTPUT);
pinMode(BUTTON, INPUT);

}

void loop() {

  val = digitalRead(BUTTON); 
  if (val == HIGH) {
    state = 1 -state;
  }
if (state == 1){
  digitalRead(LED, HIGH);
}
else {
  digitalWrite(LED, LOW);
}

}
  digitalRead(LED, HIGH);

That doesn’t look right. Do you mean digitalWrite?

True :)

Tnx

If you fix that one, it should compile - I can't see why you would get the error messages you quoted.

I fix it with advice of that guy before :)

But just one question,

why the book use code with

const int LED=13 and const int BUTTON

I understand that pin 13, will be main pin for LED all the times, if i don't replace it, but the same code work fine without const ?

And i notice one more thing if i run the same code with const, Sketch uses 1,002 bytes If i remove const and use just int type of data i see: 1,036 bytes

With more typing i get less bytes, with less typing i get more used bytes. I try to understand more about Wiring and processing Language so any opinion ?

milorad: const int LED=13 and const int BUTTON

I understand that pin 13, will be main pin for LED all the times, if i don't replace it, but the same code work fine without const ?

using a constant will assist in debug. the compiler will notice if you try to put another value to LED or BUTTON.

you can try it:

const int ledPin = 5;

void setup()
{
  ledPin = 10;
}

void loop()
{
  
}

you will get an error when you try to compile

As i said before

I understand that  pin 13, will be main pin for LED all the times, if i don't replace it, but 
the same code work fine without const

I m avers of const as that, but this 1,002 1,036

The compiler is doing different things with your sketch depending on whether or not you used "const", so generates different amounts of code. It's no big deal.

But it is interesting that int take more space then const int.

But my problem is solved so we can lock this topic

I'd ask "why use an "int" for a pin number?" , but maybe that's another question.