Kompletter Nyan cat Song

This commit is contained in:
2016-09-11 13:57:07 +02:00
parent a8ca0acd0b
commit bece9fee21
4 changed files with 525 additions and 74 deletions

8
main.c
View File

@@ -1,7 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include "player.h" #include "player.h"
#include "song.h"
void shutdown(void) { void shutdown(void) {
//Diese Methode wird von beim beenden aufgerufen. //Diese Methode wird von beim beenden aufgerufen.
@@ -15,6 +15,10 @@ int main(void) {
exit(0); exit(0);
} }
playIntro(); //Intro
play(intro, noteDurations, introlength);
//Main theme
play(melody, melodyNoteDurations, songlength);
return 0; return 0;
} }

View File

@@ -1,75 +1,9 @@
#include <wiringPi.h> #include <wiringPi.h>
#include <softTone.h> #include <softTone.h>
#include "player.h" #include "player.h"
#include "pitches.h"
#define PIN 0 //Realer pin 11 #define PIN 0 //Realer pin 11
const unsigned int introlength = 25;
int intro[] = {
//intro
NOTE_DS5,
NOTE_E5,
NOTE_FS5,
NOTE_B5,
NOTE_DS5,
NOTE_E5,
NOTE_FS5,
NOTE_B5,
NOTE_CS6,
NOTE_DS6,
NOTE_CS6,
NOTE_AS5,
NOTE_B5,
NOTE_FS5,
NOTE_DS5,
NOTE_E5,
NOTE_FS5,
NOTE_B5,
NOTE_CS6,
NOTE_AS5,
NOTE_B5,
NOTE_CS6,
NOTE_E6,
NOTE_DS6,
NOTE_E6,
NOTE_B5,
};
// Noten Dauern: 4 --> Viertel Note, 8 --> Achtel Note usw.
int noteDurations[] = {
16,
16,
8,
8,
16,
16,
16,
16,
16,
16,
16,
16,
8, //13
8,
16,
16,
8,
8,
16,
16,
16,
16,
16,
16,
16,
16 //25 intro
};
int setupSoftTone(void) { int setupSoftTone(void) {
int returncode = 0; int returncode = 0;
@@ -78,15 +12,15 @@ int setupSoftTone(void) {
return returncode; // >0 --> error return returncode; // >0 --> error
} }
void playIntro(void) { void play(int *notes, int *durations, int songlength) {
int nDuration, pauseBetweenNotes, thisNote; int nDuration, pauseBetweenNotes, thisNote;
for (thisNote = 0; thisNote < introlength; thisNote++) { for (thisNote = 0; thisNote < songlength; thisNote++) {
/** /**
* Um die Zeit der Note zu berechnen muss eine Sekunde durch * Um die Zeit der Note zu berechnen muss eine Sekunde durch
* die Laenge der Note geteilt werden. * die Laenge der Note geteilt werden.
*/ */
nDuration = 1000 / noteDurations[thisNote]; nDuration = 1000 / *(durations + thisNote);
softToneWrite(PIN, intro[thisNote]); softToneWrite(PIN, *(notes + thisNote));
delay(nDuration); delay(nDuration);
softToneWrite(PIN, 0); softToneWrite(PIN, 0);
/** /**
@@ -99,5 +33,5 @@ void playIntro(void) {
delay(pauseBetweenNotes); delay(pauseBetweenNotes);
// Sicherheitshalber Ton ausschalten // Sicherheitshalber Ton ausschalten
softToneWrite(PIN, 0); softToneWrite(PIN, 0);
} }
} }

View File

@@ -1,2 +1,2 @@
int setupSoftTone(void); int setupSoftTone(void);
void playIntro(void); void play(int *notes, int *durations, int songlength);

513
song.h Normal file
View File

@@ -0,0 +1,513 @@
#include "pitches.h"
const unsigned int introlength = 25;
const unsigned int songlength = 216;
int intro[] = {
//intro
NOTE_DS5,
NOTE_E5,
NOTE_FS5,
NOTE_B5,
NOTE_DS5,
NOTE_E5,
NOTE_FS5,
NOTE_B5,
NOTE_CS6,
NOTE_DS6,
NOTE_CS6,
NOTE_AS5,
NOTE_B5,
NOTE_FS5,
NOTE_DS5,
NOTE_E5,
NOTE_FS5,
NOTE_B5,
NOTE_CS6,
NOTE_AS5,
NOTE_B5,
NOTE_CS6,
NOTE_E6,
NOTE_DS6,
NOTE_E6,
NOTE_B5,
};
// Noten Dauern: 4 --> Viertel Note, 8 --> Achtel Note usw.
int noteDurations[] = {
16,
16,
8,
8,
16,
16,
16,
16,
16,
16,
16,
16,
8, //13
8,
16,
16,
8,
8,
16,
16,
16,
16,
16,
16,
16,
16 //25 intro
};
int melody[] = {
//A
NOTE_FS5,
NOTE_GS5,
NOTE_DS5,
NOTE_DS5,
REST,
NOTE_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
16,
16,
16,
16,
16,
8,
8,
8,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
8,
8,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
8,
16,
16,
16,
16,
16,
16,
16,
16,
8,
8,
8,
8,
8,
16,
16,
16,
16,
16,
16,
16,
16,
8,
8,
8,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
8,
8,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
8,
16,
16,
16,
16,
16,
16,
16,
16,
8,
8,
8,
//
8,
16,
16,
8,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
8,
8,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
8,
16,
16,
8,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
//
8,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
8,
8,
//
8,
16,
16,
8,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
8,
8,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
8,
16,
16,
8,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
//
8,
16,
16,
16,
16,
16,
16,
16,
16,
16,
16,
8,
8
};