1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| #include <wiringPi.h> #include <softTone.h> #include <stdio.h>
#define BuzPin 0
#define CL1 131 #define CL2 147 #define CL3 165 #define CL4 175 #define CL5 196 #define CL6 221 #define CL7 248
#define CM1 262 #define CM2 294 #define CM3 330 #define CM4 350 #define CM5 393 #define CM6 441 #define CM7 495
#define CH1 525 #define CH2 589 #define CH3 661 #define CH4 700 #define CH5 786 #define CH6 882 #define CH7 990
int song_1[] = {CM3,CM5,CM6,CM3,CM2,CM3,CM5,CM6,CH1,CM6,CM5,CM1,CM3,CM2, CM2,CM3,CM5,CM2,CM3,CM3,CL6,CL6,CL6,CM1,CM2,CM3,CM2,CL7, CL6,CM1,CL5};
int beat_1[] = {1,1,3,1,1,3,1,1,1,1,1,1,1,1,3,1,1,3,1,1,1,1,1,1,1,2,1,1, 1,1,1,1,1,1,3};
int song_2[] = {CM1,CM1,CM1,CL5,CM3,CM3,CM3,CM1,CM1,CM3,CM5,CM5,CM4,CM3,CM2, CM2,CM3,CM4,CM4,CM3,CM2,CM3,CM1,CM1,CM3,CM2,CL5,CL7,CM2,CM1 };
int beat_2[] = {1,1,1,3,1,1,1,3,1,1,1,1,1,1,3,1,1,1,2,1,1,1,3,1,1,1,3,3,2,3};
int main(void) { int i, j;
if(wiringPiSetup() == -1){ printf("setup wiringPi failed !"); return 1; }
if(softToneCreate(BuzPin) == -1){ printf("setup softTone failed !"); return 1; }
while(1){ printf("music is being played...\n");
for(i=0;i<sizeof(song_1)/4;i++){ printf("1\n"); softToneWrite(BuzPin, song_1[i]); printf("2\n"); delay(beat_1[i] * 500); printf("3\n"); }
for(i=0;i<sizeof(song_2)/4;i++){ printf("a\n"); softToneWrite(BuzPin, song_2[i]); printf("b\n"); delay(beat_2[i] * 500); printf("c\n"); } }
return 0; }
|