Having a blast with my new Starter Kit. I’m up to project 07 and I’m having an array problem and a logic problem as well. I’ve pasted the code as shown in the book at the end of this post. Two problems
PROBLEM 1
1st if I check this code it tells me an error on line 4:
"conflicting declaration 'int buttons [0]'"
'buttons' has a previous declaration as 'int buttons [6]'"
So it doesn’t like my int buttons[0] = 2; statement. I’ve tried losing the int and changing = to == both to no avail. If I comment out this line it compiles fine loads and only the second button plays a note.
PROBLEM 2
I don’t see what buttons does after this. I thought it would be used to check the 4 physical buttons on the breadboard but those are the only two places it is referenced in the code. Seems like something is missing with this array.
Any help appreciated.
Dennis
------------begin code this is the complete source ---------
int buttons[6];
// set up an array with 6 integers
int buttons[0] = 2;
// give the first element of the array the value 2 note that it counts from zero
int notes[] = {262, 294, 330, 349};
//corresponds to the notes C, D, E and F
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);
}
}
Moderator edit: error message rendered legible