Uno R4 Starter Kit

Have been working through the Starter Kit Book and have found many discrepancies.

In the Keyboard Instrument (Project 7) sketch provided in the book, received error:

C:\Users\river\AppData\Local\Temp.arduinoIDE-unsaved2026113-972-b3ezh8.g8z7w\sketch_feb13a\sketch_feb13a.ino:2:14: error: conflicting declaration 'int buttons [0]'
int buttons[0] = 2; // give the first element of the array the value 2
^
C:\Users\river\AppData\Local\Temp.arduinoIDE-unsaved2026113-972-b3ezh8.g8z7w\sketch_feb13a\sketch_feb13a.ino:1:5: note: previous declaration as 'int buttons [6]'
int buttons[6]; // set up array with 6 integers
^~~~~~~
exit status 1

Compilation error: conflicting declaration 'int buttons [0]'

Here is the sketch as presented in the book:

int buttons[6]; // set up array with 6 integers
int buttons[0] = 2; // give the first element of the array the value 2 
int notes[] = {262, 294, 330, 349};
 void setup() {
  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 <=515) {
    tone(8, notes[2]);
  }
  else if(keyVal >=5 && keyVal <=10){
    tone(8, notes[3]);
  }
  else{
    noTone(8);
  }
 }
 
Attempting to use <code/> tags, please advise if it is working for me  :^)
AI tells me that the line: int buttons[0] = 2; is incorrect in that int has been declared in the prior line. Then deleting the int still get error and AI tells me that the line does not belong in the global declaration and should be in void setup() instead. That correction allows the sketch to compile and run. 

My vision was that this was a book to show the correct structure of code, and demonstrate the uses of the board with examples that work. What my experience so far has been is that I need to find the problems in the code given and fix them to get it to function. Is this the aim of the kit? If so, my direction in following the written pages will have a different prospective. 

I understand that I am new to the code, the syntax, structure, verbiage, and a lot more. That was the purpose of purchasing the kit. To learn, become familiar with this, become at least somewhat decent at understanding it. I guess repairing is a good way to learn, but it not a very positive feeling to need to fix so much while learning.

Not trying to be negative or sour, just trying to understand. Coding has been an interest for a few years and have not yet found a solid positive way to learn it. I am getting a bit better and understanding more. It has been a frustrating journey so far. My background is not electronics, mechanics, and can reason through much if I understand what things are. 

Well, thank you to anyone that reads this far. And appreciation to anyone that wants to help. Want to understand and learn, have helped many in the past to understand and learn mechanics, so I know there are those who like to help others.

Well I can see that the code tags worked, though the text after the code was included in the code… not sure what was done incorrectly :^/

Just select the code when using tags.

It's an error.

I used the code tag and pasted the code. Not sure how my text afterward was included in the code window, how to end the code tag might be where I went wrong?

Yes, it is an error. Why would it be presented in the book?

Attempting to make sense of the problem.

I don't see any sense, errors don't necessarily have.. :wink:
You can edit your post and move the tags where code ends and text starts.
You see the outcome on the preview window on the right.

You are trying to execute codde OUTSIDE any procedure/function. The line

  buttons[0] = 2; should be in the setup function.

Let me try it…

int buttons[6]; // set up array with 6 integers
int buttons[0] = 2; // give the first element of the array the value 2 
int notes[] = {262, 294, 330, 349};
 void setup() {
  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 <=515) {
    tone(8, notes[2]);
  }
  else if(keyVal >=5 && keyVal <=10){
    tone(8, notes[3]);
  }
  else{
    noTone(8);
  }
 }
 

OK, is this better?

Not seeing option for preview window….

Screenshot of this reply....

int buttons[6]; // set up array with 6 integers
int buttons[0] = 2; // give the first element of the array the value 2 
int notes[] = {262, 294, 330, 349};
 void setup() {
  Serial.begin(9600);

See the window on the right.

Yes, found that to be true. Once the code was moved to void setup() it would compile.

Why would the code in the book be incorrect? That is my question.

How does one get the window on the right?

Do not see option to get that…

Post a picture of the page in the book, I don;t KNOW that it is incorrect.

this is actually defining an array of ints with zero elements.

the way to statically, at compile time is

int buttons[6] = ( 2, 3, 4 };   // specifiy non-zero values for 1st 3 elements

Do you see it like this? Try the arrows on low right corner

Yep, the book is wrong. What book is it?

I make errors, you make errors, book writers make errors, AI make lot of errors...

that's how it goes, we need to navigate with errors...

no, it is not there

It came in the Arduino R4 Starter Kit

Somewhere in the book will be info for support etc, let them know it's wrong.