Simple fish eat program

Dependencies:   mbed mbed-rtos N5110 ShiftReg Tone

Committer:
el18a2k
Date:
Wed Apr 21 16:26:26 2021 +0000
Revision:
13:183bd19f3d7d
Parent:
12:20ac766b3175
Child:
14:f1552b691274
bugs seem to of disapeared

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el18a2k 3:8c9c9794bcf2 1 #include "Sound.h"
el18a2k 3:8c9c9794bcf2 2 #include "Tone.h"
el18a2k 3:8c9c9794bcf2 3
el18a2k 12:20ac766b3175 4 //creates the main theme to be played
el18a2k 3:8c9c9794bcf2 5 void Sound::mainTheme(Tone &dac){
el18a2k 3:8c9c9794bcf2 6
el18a2k 13:183bd19f3d7d 7 //create an array of notes to be played
el18a2k 3:8c9c9794bcf2 8 const int mainTheme_note_array[] = {
el18a2k 3:8c9c9794bcf2 9 NOTE_C3,
el18a2k 3:8c9c9794bcf2 10
el18a2k 3:8c9c9794bcf2 11 NOTE_C3, NOTE_A3, NOTE_C3, NOTE_G3, //bar 1
el18a2k 3:8c9c9794bcf2 12 NOTE_C3, NOTE_F3, NOTE_C3, NOTE_E3,
el18a2k 3:8c9c9794bcf2 13 NOTE_D3, NOTE_E3, NOTE_F3, NOTE_E3,
el18a2k 3:8c9c9794bcf2 14 NOTE_D3, NOTE_C3, 0,
el18a2k 3:8c9c9794bcf2 15
el18a2k 3:8c9c9794bcf2 16 NOTE_C3,
el18a2k 3:8c9c9794bcf2 17
el18a2k 3:8c9c9794bcf2 18 NOTE_C3, NOTE_A3, NOTE_C3, NOTE_G3, //bar 2
el18a2k 3:8c9c9794bcf2 19 NOTE_C3, NOTE_F3, NOTE_C3, NOTE_E3,
el18a2k 3:8c9c9794bcf2 20 NOTE_D3, NOTE_E3, NOTE_F3, NOTE_E3,
el18a2k 3:8c9c9794bcf2 21 NOTE_D3, NOTE_C3, 0,
el18a2k 3:8c9c9794bcf2 22
el18a2k 3:8c9c9794bcf2 23 NOTE_C3,
el18a2k 3:8c9c9794bcf2 24
el18a2k 3:8c9c9794bcf2 25 NOTE_C3, NOTE_A3, NOTE_C3, NOTE_G3, //bar 3
el18a2k 3:8c9c9794bcf2 26 NOTE_C3, NOTE_F3, NOTE_C3, NOTE_E3,
el18a2k 3:8c9c9794bcf2 27 NOTE_D3, NOTE_E3, NOTE_F3, NOTE_E3,
el18a2k 3:8c9c9794bcf2 28 NOTE_D3, NOTE_C3, 0,
el18a2k 3:8c9c9794bcf2 29
el18a2k 3:8c9c9794bcf2 30 NOTE_C3,
el18a2k 3:8c9c9794bcf2 31
el18a2k 3:8c9c9794bcf2 32 NOTE_C3, NOTE_A3, NOTE_C3, NOTE_G3, //bar 4
el18a2k 3:8c9c9794bcf2 33 NOTE_C3, NOTE_F3, NOTE_C3, NOTE_E3,
el18a2k 3:8c9c9794bcf2 34 NOTE_D3, NOTE_E3, NOTE_F3, NOTE_E3,
el18a2k 3:8c9c9794bcf2 35 NOTE_D3, NOTE_C3, 0,
el18a2k 3:8c9c9794bcf2 36
el18a2k 3:8c9c9794bcf2 37 NOTE_C4,
el18a2k 3:8c9c9794bcf2 38
el18a2k 3:8c9c9794bcf2 39 NOTE_C4, NOTE_A4, NOTE_C4, NOTE_G4, //bar 5
el18a2k 3:8c9c9794bcf2 40 NOTE_C4, NOTE_F4, NOTE_C4, NOTE_E4,
el18a2k 3:8c9c9794bcf2 41 NOTE_D4, NOTE_E4, NOTE_F4, NOTE_E4,
el18a2k 3:8c9c9794bcf2 42 NOTE_D4, NOTE_C4, 0,
el18a2k 3:8c9c9794bcf2 43
el18a2k 3:8c9c9794bcf2 44 NOTE_C4,
el18a2k 3:8c9c9794bcf2 45
el18a2k 3:8c9c9794bcf2 46 NOTE_C4, NOTE_A4, NOTE_C4, NOTE_G4, //bar 6
el18a2k 3:8c9c9794bcf2 47 NOTE_C4, NOTE_F4, NOTE_C4, NOTE_E4,
el18a2k 3:8c9c9794bcf2 48 NOTE_D4, NOTE_E4, NOTE_F4, NOTE_E4,
el18a2k 3:8c9c9794bcf2 49 NOTE_D4, NOTE_C4, 0,
el18a2k 3:8c9c9794bcf2 50
el18a2k 3:8c9c9794bcf2 51 NOTE_C3,
el18a2k 3:8c9c9794bcf2 52
el18a2k 3:8c9c9794bcf2 53 NOTE_C3, NOTE_A3, NOTE_C3, NOTE_G3, //bar 7
el18a2k 3:8c9c9794bcf2 54 NOTE_C3, NOTE_F3, NOTE_C3, NOTE_E3,
el18a2k 3:8c9c9794bcf2 55 NOTE_D3, NOTE_E3, NOTE_F3, NOTE_E3,
el18a2k 3:8c9c9794bcf2 56 NOTE_D3, NOTE_C3, 0,
el18a2k 3:8c9c9794bcf2 57
el18a2k 3:8c9c9794bcf2 58 NOTE_C3,
el18a2k 3:8c9c9794bcf2 59
el18a2k 3:8c9c9794bcf2 60 NOTE_C3, NOTE_A3, NOTE_C3, NOTE_G3, //bar 8
el18a2k 3:8c9c9794bcf2 61 NOTE_C3, NOTE_F3, NOTE_C3, NOTE_E3,
el18a2k 3:8c9c9794bcf2 62 NOTE_D3, NOTE_E3, NOTE_F3, NOTE_E3,
el18a2k 3:8c9c9794bcf2 63 NOTE_D3, NOTE_C3, 0,
el18a2k 3:8c9c9794bcf2 64 };
el18a2k 3:8c9c9794bcf2 65
el18a2k 13:183bd19f3d7d 66 //create an array defining the duration of each note
el18a2k 3:8c9c9794bcf2 67 const int mainTheme_note_duration_array[] = {
el18a2k 3:8c9c9794bcf2 68
el18a2k 3:8c9c9794bcf2 69 8,
el18a2k 3:8c9c9794bcf2 70
el18a2k 3:8c9c9794bcf2 71 8,8,8,8, //bar 1
el18a2k 3:8c9c9794bcf2 72 8,8,8,8,
el18a2k 3:8c9c9794bcf2 73 8,8,8,8,
el18a2k 3:8c9c9794bcf2 74 8,8,8,
el18a2k 3:8c9c9794bcf2 75
el18a2k 3:8c9c9794bcf2 76 8,
el18a2k 3:8c9c9794bcf2 77
el18a2k 3:8c9c9794bcf2 78 8,8,8,8,//bar 2
el18a2k 3:8c9c9794bcf2 79 8,8,8,8,
el18a2k 3:8c9c9794bcf2 80 8,8,8,8,
el18a2k 3:8c9c9794bcf2 81 8,8,8,
el18a2k 3:8c9c9794bcf2 82
el18a2k 3:8c9c9794bcf2 83 8,
el18a2k 3:8c9c9794bcf2 84
el18a2k 3:8c9c9794bcf2 85 8,8,8,8,//bar 3
el18a2k 3:8c9c9794bcf2 86 8,8,8,8,
el18a2k 3:8c9c9794bcf2 87 8,8,8,8,
el18a2k 3:8c9c9794bcf2 88 8,8,8,
el18a2k 3:8c9c9794bcf2 89
el18a2k 3:8c9c9794bcf2 90 8,
el18a2k 3:8c9c9794bcf2 91
el18a2k 3:8c9c9794bcf2 92 8,8,8,8,//bar 4
el18a2k 3:8c9c9794bcf2 93 8,8,8,8,
el18a2k 3:8c9c9794bcf2 94 8,8,8,8,
el18a2k 3:8c9c9794bcf2 95 8,8,8,
el18a2k 3:8c9c9794bcf2 96
el18a2k 3:8c9c9794bcf2 97 8,
el18a2k 3:8c9c9794bcf2 98
el18a2k 3:8c9c9794bcf2 99 8,8,8,8, //bar 5
el18a2k 3:8c9c9794bcf2 100 8,8,8,8,
el18a2k 3:8c9c9794bcf2 101 8,8,8,8,
el18a2k 3:8c9c9794bcf2 102 8,8,8,
el18a2k 3:8c9c9794bcf2 103
el18a2k 3:8c9c9794bcf2 104 8,
el18a2k 3:8c9c9794bcf2 105
el18a2k 3:8c9c9794bcf2 106 8,8,8,8,//bar 6
el18a2k 3:8c9c9794bcf2 107 8,8,8,8,
el18a2k 3:8c9c9794bcf2 108 8,8,8,8,
el18a2k 3:8c9c9794bcf2 109 8,8,8,
el18a2k 3:8c9c9794bcf2 110
el18a2k 3:8c9c9794bcf2 111 8,
el18a2k 3:8c9c9794bcf2 112
el18a2k 3:8c9c9794bcf2 113 8,8,8,8,//bar 7
el18a2k 3:8c9c9794bcf2 114 8,8,8,8,
el18a2k 3:8c9c9794bcf2 115 8,8,8,8,
el18a2k 3:8c9c9794bcf2 116 8,8,8,
el18a2k 3:8c9c9794bcf2 117
el18a2k 3:8c9c9794bcf2 118 8,
el18a2k 3:8c9c9794bcf2 119
el18a2k 3:8c9c9794bcf2 120 8,8,8,8,//bar 8
el18a2k 3:8c9c9794bcf2 121 8,8,8,8,
el18a2k 3:8c9c9794bcf2 122 8,8,8,8,
el18a2k 3:8c9c9794bcf2 123 8,8,8,
el18a2k 3:8c9c9794bcf2 124
el18a2k 3:8c9c9794bcf2 125 };
el18a2k 3:8c9c9794bcf2 126
el18a2k 13:183bd19f3d7d 127 n = sizeof(mainTheme_note_array)/sizeof(int); //determine duration
el18a2k 13:183bd19f3d7d 128 dac.play_melody(n,mainTheme_note_array,mainTheme_note_duration_array,60.0,false); //play melody
el18a2k 13:183bd19f3d7d 129 wait_ms(100); //let melody fully play out
el18a2k 3:8c9c9794bcf2 130 }