Arduino project 07 LIED TO ME!!

First thing in the code, It says to write what is in the photo. but I get this error message: "exit status 1 Compilation error: conflicting declaration 'int buttons [0]" What is the problem here.
No description
12 Replies
AnonEngineering
AnonEngineering3mo ago
c++
int buttons[6];
buttons[0] = 2;
c++
int buttons[6];
buttons[0] = 2;
otherwise it's trying to redeclare the buttons array
TheStudier
TheStudierOP3mo ago
altight weird that it shows this wrongly thanks Compilation error: 'buttons' does not name a type this is what I get now
AnonEngineering
AnonEngineering3mo ago
you need to declare the button array as type integer but you can only declare it once...
TheStudier
TheStudierOP2mo ago
int notes[6]; notes[0]=2; i switched from button to notes but it doesn't work
AnonEngineering
AnonEngineering2mo ago
share the complete code, that makes no sense...
c++
int buttons[6];

void setup() {
Serial.begin(9600);
buttons[0] = 2;
buttons[1] = 3;
buttons[2] = 4;
buttons[3] = 5;
buttons[4] = 6;
buttons[5] = 7;
for (int i = 0; i < 6; i++) {
Serial.println(buttons[i]);
}
}

void loop() {}
c++
int buttons[6];

void setup() {
Serial.begin(9600);
buttons[0] = 2;
buttons[1] = 3;
buttons[2] = 4;
buttons[3] = 5;
buttons[4] = 6;
buttons[5] = 7;
for (int i = 0; i < 6; i++) {
Serial.println(buttons[i]);
}
}

void loop() {}
Exodus
Exodus2mo ago
🧐
TheStudier
TheStudierOP2mo ago
int buttons[6]; // set up an 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); } there Its arduino project number 07 a mini keyboard instrument
AnonEngineering
AnonEngineering2mo ago
i don't see any need for buttons at all, that looks like it's reading a resistor divider on A0 int keyVal = analogRead(A0); that code came out of a project book???
TheStudier
TheStudierOP2mo ago
I copied this code from the project book
TheStudier
TheStudierOP2mo ago
tyy
Chiket
Chiket2mo ago
You don’t need the Int for the second line

Did you find this page helpful?