ELEC2645 (2018/19) / Mbed 2 deprecated el17rrrs

Dependencies:   mbed Gamepad N5110 mbed-rtos

Committer:
RexRoshan
Date:
Thu May 09 09:49:35 2019 +0000
Revision:
0:d9cf94b41df3
Documentation has been completed and the code has been slightly modified

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RexRoshan 0:d9cf94b41df3 1 #include "Music.h"
RexRoshan 0:d9cf94b41df3 2
RexRoshan 0:d9cf94b41df3 3 Music::Music()
RexRoshan 0:d9cf94b41df3 4 {
RexRoshan 0:d9cf94b41df3 5
RexRoshan 0:d9cf94b41df3 6 }
RexRoshan 0:d9cf94b41df3 7
RexRoshan 0:d9cf94b41df3 8 Music::~Music()
RexRoshan 0:d9cf94b41df3 9 {
RexRoshan 0:d9cf94b41df3 10
RexRoshan 0:d9cf94b41df3 11 }
RexRoshan 0:d9cf94b41df3 12
RexRoshan 0:d9cf94b41df3 13 void Music::intro_song(Gamepad &pad) // introduction song for the game
RexRoshan 0:d9cf94b41df3 14 {
RexRoshan 0:d9cf94b41df3 15 while(pad.check_event(Gamepad::START_PRESSED) == false){
RexRoshan 0:d9cf94b41df3 16 pad.tone(293.665, 2);
RexRoshan 0:d9cf94b41df3 17 wait(0.8); // thread wait so that two loops can simulatneously run
RexRoshan 0:d9cf94b41df3 18 if(pad.check_event(Gamepad::START_PRESSED) == true){break;} // break if start button has been pressed
RexRoshan 0:d9cf94b41df3 19 pad.tone(311.127, 2);
RexRoshan 0:d9cf94b41df3 20 wait(0.8);
RexRoshan 0:d9cf94b41df3 21 if(pad.check_event(Gamepad::START_PRESSED) == true){break;}
RexRoshan 0:d9cf94b41df3 22 pad.tone(329.628, 2);
RexRoshan 0:d9cf94b41df3 23 wait(0.8);
RexRoshan 0:d9cf94b41df3 24 if(pad.check_event(Gamepad::START_PRESSED) == true){break;}
RexRoshan 0:d9cf94b41df3 25 pad.tone(349.228, 2);
RexRoshan 0:d9cf94b41df3 26 wait(0.8);
RexRoshan 0:d9cf94b41df3 27 if(pad.check_event(Gamepad::START_PRESSED) == true){break;}
RexRoshan 0:d9cf94b41df3 28 }
RexRoshan 0:d9cf94b41df3 29 }
RexRoshan 0:d9cf94b41df3 30
RexRoshan 0:d9cf94b41df3 31 void Music::mission_success(Gamepad &pad) // success song
RexRoshan 0:d9cf94b41df3 32 {
RexRoshan 0:d9cf94b41df3 33 //triplets
RexRoshan 0:d9cf94b41df3 34 pad.tone(207.65,0.18);
RexRoshan 0:d9cf94b41df3 35 wait(0.2);
RexRoshan 0:d9cf94b41df3 36 pad.tone(207.65,0.18);
RexRoshan 0:d9cf94b41df3 37 wait(0.2);
RexRoshan 0:d9cf94b41df3 38 pad.tone(207.65,0.18);
RexRoshan 0:d9cf94b41df3 39 wait(0.2);
RexRoshan 0:d9cf94b41df3 40 // 3 beats
RexRoshan 0:d9cf94b41df3 41 pad.tone(261.63,0.28);
RexRoshan 0:d9cf94b41df3 42 wait(0.3);
RexRoshan 0:d9cf94b41df3 43 pad.tone(207.65,0.28);
RexRoshan 0:d9cf94b41df3 44 wait(0.3);
RexRoshan 0:d9cf94b41df3 45 pad.tone(261.63,0.28);
RexRoshan 0:d9cf94b41df3 46 wait(0.3);
RexRoshan 0:d9cf94b41df3 47 pad.tone(261.63,0.28);
RexRoshan 0:d9cf94b41df3 48 wait(0.30);
RexRoshan 0:d9cf94b41df3 49 pad.tone(207.65,0.28);
RexRoshan 0:d9cf94b41df3 50 wait(0.30);
RexRoshan 0:d9cf94b41df3 51 pad.tone(261.63,0.28);
RexRoshan 0:d9cf94b41df3 52 wait(0.30);
RexRoshan 0:d9cf94b41df3 53 pad.tone(311.13,1.2);
RexRoshan 0:d9cf94b41df3 54 wait(1.2);
RexRoshan 0:d9cf94b41df3 55 wait(2.4);
RexRoshan 0:d9cf94b41df3 56 };
RexRoshan 0:d9cf94b41df3 57
RexRoshan 0:d9cf94b41df3 58 void Music::mission_fail(Gamepad &pad) // failure song
RexRoshan 0:d9cf94b41df3 59 {
RexRoshan 0:d9cf94b41df3 60 pad.tone(233.0,0.5);
RexRoshan 0:d9cf94b41df3 61 wait(0.5);
RexRoshan 0:d9cf94b41df3 62 pad.tone(184.0,0.5);
RexRoshan 0:d9cf94b41df3 63 wait(0.5);
RexRoshan 0:d9cf94b41df3 64 pad.tone(174.0,2.0);
RexRoshan 0:d9cf94b41df3 65 wait(1.0);
RexRoshan 0:d9cf94b41df3 66
RexRoshan 0:d9cf94b41df3 67 };