Newbie
Registriert seit: Dec 2009
Beiträge: 67
Bedankt: 20
|
hallo
ein bekannter hat mir geholfen wenns jemand interessiert hier ist das fehlerfreie programm
ich hatte die Pin declaration vergessen und noch ein paar andere kleine fehler gemacht
Zitat:
#include "pitches.h"
// notes in the melody:
int melody[] = {
NOTE_C3, NOTE_D3, NOTE_E3, NOTE_F3, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_A3,
NOTE_A3, NOTE_A3, NOTE_G3, NOTE_A3, NOTE_A3, NOTE_A3, NOTE_A3, NOTE_G3,
NOTE_F3, NOTE_F3, NOTE_F3, NOTE_F3, NOTE_E3, NOTE_E3, NOTE_D3, NOTE_D3,
NOTE_D3, NOTE_D3, NOTE_C3};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
4, 4, 4, 4, 2, 2, 4, 4,
4, 4, 1, 4, 4, 4, 4, 1,
4, 4, 4, 4, 2, 2, 4, 4,
4, 4, 1 };
void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 27; thisNote++) {
// to calculate the note duration, take one second
// divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000/noteDurations[thisNote];
tone(8, melody[thisNote],noteDuration);
if(melody[thisNote] == NOTE_C3) {
digitalWrite(2, HIGH);
}
if(melody[thisNote] == NOTE_D3) {
digitalWrite(3, HIGH);
}
if(melody[thisNote] == NOTE_E3) {
digitalWrite(4, HIGH);
}
if(melody[thisNote] == NOTE_F3) {
digitalWrite(5, HIGH);
}
if(melody[thisNote] == NOTE_G3) {
digitalWrite(6, HIGH);
}
if(melody[thisNote] == NOTE_A3) {
digitalWrite(7, HIGH);
}
// if (x > 120) digitalWrite(LEDpin, HIGH);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
digitalWrite(2, LOW);
digitalWrite(3, LOW);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
// stop the tone playing:
noTone( ;
}
}
void loop() {
// no need to repeat the melody.
}
|
jetz wird alle meine entchen abgespielt und immer wenn ein anderer Ton kommt geht eine andere LED an natürlich schön in rheinfolge auf gebaut
MFG GayFish
|