Arduino-Starterkit Projekt 7, brauche Hilfe!

Gast #4730490
Lesenswert?

Hallo liebe Community


Ich habe mir das Arduino Startet-Kit bestellt und komme eigentlich ganz 
gut voran. Doch jetzt bin ich beim Projekt 7 angelangt, und da zeigt es 
mir immer folgendes Problem an, doch ich werde nicht schlau draus.

Hier ist der Code:


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);
 }
}




Und so sieht die Fehlermeldung aus:

Arduino: 1.7.10 (Windows 7), Platine: "Arduino Uno"

C:\Program Files (x86)\Arduino/hardware/tools/avr/bin/avr-g++ -c -g -Os 
-w -fno-exceptions -ffunction-sections -fdata-sections 
-fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L 
-DARDUINO=107010 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -IC:\Program Files 
(x86)\Arduino\hardware\arduino\avr\cores\arduino -IC:\Program Files 
(x86)\Arduino\hardware\arduino\avr\variants\standard 
C:\Users\CHRIST~1\AppData\Local\Temp\build8652659257394287752.tmp\sketch 
_sep24b.cpp  -o 
C:\Users\CHRIST~1\AppData\Local\Temp\build8652659257394287752.tmp\sketch 
_sep24b.cpp.o

sketch_sep24b.ino:4:14: error: conflicting declaration 'int buttons [0]'

sketch_sep24b.ino:1:5: error: 'buttons' has a previous declaration as 
'int buttons [6]'

Fehler beim Kompilieren.




Ich hoffe, jemand von euch weiss weiter.

MFG
#4730498
Lesenswert?

Hallo,

Du deklarierst ein int-Array int buttons[6];
Dann versuchts Du ein int-Array mit gleichem Namen zu deklarieren:
int buttons[0] = 2;

Das geht nicht. Das soll ja auch eine Zuweisung für Element 0 des schon 
deklarierten Array sein, da gehöt also kein int davor.

buttons[0] = 2;

Gruß aus Berlin
Michael

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren