Dies ist eine alte Version des Dokuments!


Inhaltsverzeichnis

Tetrismelodie

Sopran

Aufruf: playMelody( melodyTrack1, durationsTrack3, 59 )

// notes in the melody:
int melodyTrack1[] = {
  NOTE_E3, NOTE_H2, NOTE_C3, NOTE_D3, NOTE_E3, NOTE_D3, NOTE_C3, NOTE_H2,
  NOTE_A2, NOTE_A2, NOTE_C3, NOTE_E3, NOTE_D3, NOTE_C3,
  NOTE_H2, NOTE_H2, NOTE_C3, NOTE_D3, NOTE_E3,
  NOTE_C3, NOTE_A2, NOTE_A2,
  0, NOTE_D3, NOTE_F3, NOTE_A3, NOTE_G3, NOTE_F3,
  NOTE_E3, NOTE_E3, NOTE_C3, NOTE_E3, NOTE_D3, NOTE_C3,
  NOTE_H2, NOTE_H2, NOTE_C3, NOTE_D3, NOTE_E3,
  NOTE_C3, NOTE_A2, NOTE_A2, 0,
  NOTE_E2, NOTE_C2, NOTE_D2, NOTE_H1, NOTE_C2, NOTE_A1, NOTE_GS1, NOTE_H1,
  NOTE_E2, NOTE_C2, NOTE_D2, NOTE_H1, NOTE_C2, NOTE_E2, NOTE_A2, NOTE_GS2
};
  
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int durationsTrack1[] = {
  4,8,8,8,16,16,8,8,
  4,8,8,4,8,8,
  4,8,8,4,4,
  4,4,2,
  8,4,8,4,8,8,
  4,8,8,4,8,8,
  4,8,8,4,4,
  4,4,4,4,
  2,2,2,2,2,2,2,2,
  2,2,2,2,4,4,2,1
};//59

Alt

Aufruf: playMelody( melodyTrack2, durationsTrack2, 70 );

int melodyTrack2[] = {
  NOTE_H2, NOTE_GS2, NOTE_A2, NOTE_H2, NOTE_E3, NOTE_D3, NOTE_A2, NOTE_GS2,
  NOTE_E2, NOTE_E2, NOTE_A2, NOTE_C3, NOTE_H2, NOTE_A2,
  NOTE_GS2, NOTE_E2, NOTE_GS2, NOTE_A2, NOTE_H2, NOTE_C3,
  NOTE_A2, NOTE_E2, NOTE_E2,
  0, NOTE_F2, NOTE_A2, NOTE_C3, NOTE_C3, NOTE_C3, NOTE_H2, NOTE_A2,
  NOTE_G2, NOTE_G2, NOTE_E2, NOTE_G2, NOTE_A2, NOTE_G2, NOTE_F2, NOTE_E2,
  NOTE_GS2, NOTE_E2, NOTE_GS2, NOTE_A2, NOTE_H2, NOTE_GS2, NOTE_C3, NOTE_GS2,
  NOTE_A2, NOTE_E2, NOTE_E2, NOTE_E2, 0,
  NOTE_C2, NOTE_A1, NOTE_H1, NOTE_GS1, NOTE_A1, NOTE_E1, NOTE_E1, NOTE_G1,
  NOTE_C2, NOTE_A1, NOTE_H1, NOTE_GS1, NOTE_A1, NOTE_C2, NOTE_E2, NOTE_E2
};

int durationsTrack2[] = {
  4,8,8,8,16,16,8,8,
  4,8,8,4,8,8,
  8,8,8,8,4,4,
  4,4,2,
  8,4,8,8,16,16,8,8,
  4,8,8,8,16,16,8,8,
  8,8,8,8,8,8,8,8,
  8,8,4,4,4,
  2,2,2,2,2,2,2,2,
  2,2,2,2,4,4,2,1
};//77

Aufruf: playMelody( melodyTrack3, durationsTrack3, 126 )

int melodyTrack3[] = {
  NOTE_E1, NOTE_E2, NOTE_E1, NOTE_E2, NOTE_E1, NOTE_E2, NOTE_E1, NOTE_E2,
  NOTE_A1, NOTE_A2, NOTE_A1, NOTE_A2, NOTE_A1, NOTE_A2, NOTE_A1, NOTE_A2,
  NOTE_GS1, NOTE_GS2, NOTE_GS1, NOTE_GS2, NOTE_GS1, NOTE_GS2, NOTE_GS1, NOTE_GS2,
  NOTE_A1, NOTE_A2, NOTE_A1, NOTE_A2, NOTE_A1, NOTE_A2, NOTE_H1, NOTE_C2,
  NOTE_D2, NOTE_D1, 0, NOTE_D1, 0, NOTE_D1, NOTE_A1, NOTE_F1,
  NOTE_C1, NOTE_C2, 0, NOTE_C2, NOTE_C1, NOTE_G1, 0, NOTE_G1,
  NOTE_H1, NOTE_H2, 0, NOTE_H2, 0, NOTE_E2, 0, NOTE_GS2,
  NOTE_A1, NOTE_E2, NOTE_A1, NOTE_E2, NOTE_A1, 0,
  NOTE_A1, NOTE_E2, NOTE_A1, NOTE_E2, NOTE_A1, NOTE_E2, NOTE_A1, NOTE_E2,
  NOTE_GS1, NOTE_E2, NOTE_GS1, NOTE_E2, NOTE_GS1, NOTE_E2, NOTE_GS1, NOTE_E2,
  NOTE_A1, NOTE_E2, NOTE_A1, NOTE_E2, NOTE_A1, NOTE_E2, NOTE_A1, NOTE_E2,
  NOTE_GS1, NOTE_E2, NOTE_GS1, NOTE_E2, NOTE_GS1, NOTE_E2, NOTE_GS1, NOTE_E2,
  NOTE_A1, NOTE_E2, NOTE_A1, NOTE_E2, NOTE_A1, NOTE_E2, NOTE_A1, NOTE_E2,
  NOTE_GS1, NOTE_E2, NOTE_GS1, NOTE_E2, NOTE_GS1, NOTE_E2, NOTE_GS1, NOTE_E2,
  NOTE_A1, NOTE_E2, NOTE_A1, NOTE_E2, NOTE_A1, NOTE_E2, NOTE_A1, NOTE_E2,
  NOTE_GS1, NOTE_E2, NOTE_GS1, NOTE_E2, NOTE_GS1, NOTE_E2, NOTE_GS1, NOTE_E2
};

int durationsTrack3[] = {
  8,8,8,8,8,8,8,8,
  8,8,8,8,8,8,8,8,
  8,8,8,8,8,8,8,8,
  8,8,8,8,8,8,8,8,
  8,8,8,8,8,8,8,8,
  8,8,8,8,8,8,8,8,
  8,8,8,8,8,8,8,8,
  8,8,8,8,4,4,
  8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,
  8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8, 8,8,8,8,8,8,8,8,
};//126

Programm

void loop() 
{
  //playMelody( melodyTrack3, durationsTrack3, 126 );
  //playMelody( melodyTrack2, durationsTrack2, 70 );
  playMelody( melodyTrack1, durationsTrack1, 59 );
}

Die playMelody Funktion bekommt die Melodie, die Notenlängen und die Anzahl der Töne in der Melodie.

void playMelody( int* melody, int* noteDurations, int length )
{ 
  // iterate over the notes of the melody:
  for( int thisNote = 0; thisNote < length; 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 );

    // 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 );
    // stop the tone playing:
    noTone(8);
  }
}
project/arduino-kickstarter-tetris.1321706729.txt.gz · Zuletzt geändert: 14.01.2013 15:56 (Externe Bearbeitung)
Falls nicht anders bezeichnet, ist der Inhalt dieses Wikis unter der folgenden Lizenz veröffentlicht: CC Attribution-Noncommercial-Share Alike 4.0 International
Recent changes RSS feed Driven by DokuWiki