I dont understand what im doing wrong

i just bought a arduino starterkit and have been working with it most of the day now.
I try my best to go along with the tutorial, but my english isnt that great, since im from Norway.

But i just got to project 7 wich is a tone generator using 4 buttons, to make a piano sort of, but after i wrote down the code, i got a error wich i realy dont understand WHY im getting.

Could anyone please help me understand why i get this error?
because i frequently ask myself “WHY do i write or do what im doing now?” when im writing down the codes.

im very thankful for all kinds of answears.

Capture.PNG

You can not have two variables (buttons) with the same name.

A zero element array is worse than useless.

but in the arduino projectbook, they have 2 variables, exactly as i have written down in my code, what do i write instead then?

i tried to take away the "int buttons[0] = 2;" and launched the software to the arduino board. but then only one of the buttons produced sound.

but in the arduino projectbook, they have 2 variables, exactly as i have written down in my code, what do i write instead then?

I'm sure that they don't. There is something different between your code and the code in the book.

If you really believe that they do, take a picture of the page with the code on it, and post the picture.

but in the arduino projectbook, they have 2 variables, exactly as i have written down in my code,

Proof, please.

my phonecamera isnt the best, but heres what the books says. im realy confused.

Send the book back, ask for a refund.

I'm afraid he is right. I've just had a look at my copy.

Move the second statement inside setup(). Lose the int on the front.

void setup()
{
   buttons[0] = 2;
}

Then the comment will be correct.

AWOL's right, though, that code did not compile for the author, and should not have been in the book.

i wrote down the buttons[0] = 2; in the void setup(), but still only 1 of the buttons give sound. i used the monitor to see if i got response from the other buttons, but only 2 buttons give response, while the other 2 doesnt give a response on the monitor.

plz help.

heres the code i wrote down.

heres the code i wrote down.

We do not want pictures of text, unless, as in the case of the book, that is the only way to share the data. In the case of code you typed into the IDE, that is not the case.

Which pins are the switches connected to? Which pins are you reading? Which pin is producing the desired result? Which pins are not? We can NOT see what you see. You MUST tell us what you see.

Without prompting is better than with.

ok, heres the code in text(sorry) and pictures of how i connected, and what the book told me to connect to where:

int buttons[6];

int notes = {262,294,330,349};

void setup() {
buttons[0] = 2;

Serial.begin(9600);

}

void loop() {
int keyVal = analogRead(A0);
Serial.println(keyVal);

if(keyVal == 1023){
tone(8, notes[0]);
}

else if(keyVal >= 990 && keyVal <= 1010){
tone(8, notes[1]);
}
else if(keyVal >= 505 && keyVal <= 10){
tone(8, notes[2]);
}
else if(keyVal >= 5 && keyVal <= 10){
tone(8, notes[3]);
}
else{
noTone(8);
}

}

i wrote down the buttons[0] = 2; in the void setup(), but still only 1 of the buttons give sound.

I don't see anywhere apart from setup where you're using "buttons".

Please remember to use code tags when posting code.

The buttons array is not part of the project 7 sketch, it is just an example of using arrays.

  else if(keyVal >= 505 && keyVal <= 10){
    tone(8, notes[2]);
  }

That upper limit ain’t quite right.

Hint: you can find the book sketches in the IDE under File > Examples > 10.StarterKit_BasicKit