So, here is my code:
int buttons[6];
int buttons[0] = 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);
}
}
And here is the error code I am getting:
keyboard:2: error: conflicting declaration 'int buttons [0]'
int buttons[0] = 2;
^
previous declaration as 'int buttons [6]'
int buttons[6];
^
exit status 1
conflicting declaration 'int buttons [0]'
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Thank you all in advance for the help, most likely it is something simple :-p
Put this line into setup(),
int buttons[0] = 2;
as this
buttons[0] = 2;
to put a value into the 0 location.
You don't need to declare the array twice, which is what the compiler is telling you.
so your saying cut out the "int" in that line and just have that line "buttons[0] = 2"?
I just tried that and here is the error I got:
keyboard:2: error: 'buttons' does not name a type
buttons[0] = 2;
^
exit status 1
'buttons' does not name a type
Move the line into setup(), don't leave it at the top of the sketch (and start using code tags, the </> button):
int buttons[6]; // creates a global array with 6 elements, no values assigned
int notes[] = {262,294,330,349}; // global array with 4 elements, values assigned
void setup() {
Serial.begin(9600);
buttons[0] = 2; // puts a value into one of the elements
}
[/code]
It worked! Thanks man, I am a beginner and I am copying the code from a book, so something new I learned. Thank you again, appreciate the help!