Simple starter skeleton for asteroids video game.

Dependencies:   PinDetect

Committer:
jhurley31
Date:
Sat Feb 23 21:38:45 2019 +0000
Revision:
1:a6872783beca
Parent:
Speaker.h@0:0c450cb95a1e
Child:
2:30020ddfccf6
Put in speaker code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jhurley31 0:0c450cb95a1e 1 #include "mbed.h"
jhurley31 1:a6872783beca 2 #include "buzzy_siren.h"
jhurley31 1:a6872783beca 3 #include "buzzy_begin.h"
jhurley31 1:a6872783beca 4 #include "buzzy_chomp.h"
jhurley31 1:a6872783beca 5 #include "buzzy_eatghost.h"
jhurley31 1:a6872783beca 6 #include "buzzy_death.h"
jhurley31 1:a6872783beca 7 #include "buzzy_eatfruit.h"
jhurley31 1:a6872783beca 8
jhurley31 1:a6872783beca 9
jhurley31 1:a6872783beca 10 class Speaker : public PwmOut
jhurley31 0:0c450cb95a1e 11 {
jhurley31 0:0c450cb95a1e 12 public:
jhurley31 1:a6872783beca 13 enum BUZZY_Sounds {BEGIN, SIREN, CHOMP, EAT_GHOST, DEATH, EAT_FRUIT};
jhurley31 1:a6872783beca 14
jhurley31 1:a6872783beca 15 Speaker(PinName nPin):PwmOut(nPin)
jhurley31 1:a6872783beca 16 {
jhurley31 1:a6872783beca 17 m_ulAudioArrayIndex = 0;
jhurley31 1:a6872783beca 18 m_enActiveAudioArray = BEGIN;
jhurley31 1:a6872783beca 19 pAudioArray = NULL;
jhurley31 1:a6872783beca 20 }
jhurley31 1:a6872783beca 21
jhurley31 1:a6872783beca 22 void PlayNextValue()
jhurley31 1:a6872783beca 23 {
jhurley31 1:a6872783beca 24 if (pAudioArray != NULL)
jhurley31 1:a6872783beca 25 {
jhurley31 1:a6872783beca 26 write(pAudioArray[ GetNextValue() ]);
jhurley31 1:a6872783beca 27 }
jhurley31 0:0c450cb95a1e 28 }
jhurley31 1:a6872783beca 29
jhurley31 1:a6872783beca 30 void SwitchAudioFile ( const BUZZY_Sounds &newSound)
jhurley31 1:a6872783beca 31 {
jhurley31 1:a6872783beca 32 switch (newSound)
jhurley31 1:a6872783beca 33 {
jhurley31 1:a6872783beca 34 case BEGIN:
jhurley31 1:a6872783beca 35 pAudioArray = &data_BEGIN[0];
jhurley31 1:a6872783beca 36 break;
jhurley31 1:a6872783beca 37 case CHOMP:
jhurley31 1:a6872783beca 38 pAudioArray = &data_CHOMP[0];
jhurley31 1:a6872783beca 39 break;
jhurley31 1:a6872783beca 40 case EAT_GHOST:
jhurley31 1:a6872783beca 41 pAudioArray = &data_GHOST[0];
jhurley31 1:a6872783beca 42 break;
jhurley31 1:a6872783beca 43 case DEATH:
jhurley31 1:a6872783beca 44 pAudioArray = &data_DEATH[0];
jhurley31 1:a6872783beca 45 break;
jhurley31 1:a6872783beca 46 case EAT_FRUIT:
jhurley31 1:a6872783beca 47 pAudioArray = &data_EAT_FRUIT[0];
jhurley31 1:a6872783beca 48 break;
jhurley31 1:a6872783beca 49 case SIREN:
jhurley31 1:a6872783beca 50 default:
jhurley31 1:a6872783beca 51 pAudioArray = &data_SIREN[0];
jhurley31 1:a6872783beca 52 break;
jhurley31 1:a6872783beca 53 }
jhurley31 1:a6872783beca 54
jhurley31 0:0c450cb95a1e 55 }
jhurley31 1:a6872783beca 56
jhurley31 1:a6872783beca 57 unsigned int GetNextValue()
jhurley31 1:a6872783beca 58 {
jhurley31 1:a6872783beca 59 m_ulAudioArrayIndex++;
jhurley31 1:a6872783beca 60 switch (m_enActiveAudioArray)
jhurley31 1:a6872783beca 61 {
jhurley31 1:a6872783beca 62 case BEGIN:
jhurley31 1:a6872783beca 63 m_ulAudioArrayIndex %= NUM_BEGIN_ELEMENTS;
jhurley31 1:a6872783beca 64 break;
jhurley31 1:a6872783beca 65 case CHOMP:
jhurley31 1:a6872783beca 66 m_ulAudioArrayIndex %= NUM_CHOMP_ELEMENTS;
jhurley31 1:a6872783beca 67 break;
jhurley31 1:a6872783beca 68 case EAT_GHOST:
jhurley31 1:a6872783beca 69 m_ulAudioArrayIndex %= NUM_GHOST_ELEMENTS;
jhurley31 1:a6872783beca 70 break;
jhurley31 1:a6872783beca 71 case DEATH:
jhurley31 1:a6872783beca 72 m_ulAudioArrayIndex %= NUM_DEATH_ELEMENTS;
jhurley31 1:a6872783beca 73 break;
jhurley31 1:a6872783beca 74 case EAT_FRUIT:
jhurley31 1:a6872783beca 75 m_ulAudioArrayIndex %= NUM_EAT_FRUIT_ELEMENTS;
jhurley31 1:a6872783beca 76 break;
jhurley31 1:a6872783beca 77 case SIREN:
jhurley31 1:a6872783beca 78 default:
jhurley31 1:a6872783beca 79 m_ulAudioArrayIndex %= NUM_SIREN_ELEMENTS;
jhurley31 1:a6872783beca 80 break;
jhurley31 1:a6872783beca 81 }
jhurley31 1:a6872783beca 82 return m_ulAudioArrayIndex;
jhurley31 1:a6872783beca 83 }
jhurley31 0:0c450cb95a1e 84 private:
jhurley31 1:a6872783beca 85 unsigned long m_ulAudioArrayIndex;
jhurley31 1:a6872783beca 86 BUZZY_Sounds m_enActiveAudioArray;
jhurley31 1:a6872783beca 87 float *pAudioArray;
jhurley31 1:a6872783beca 88
jhurley31 0:0c450cb95a1e 89 };
jhurley31 1:a6872783beca 90
jhurley31 0:0c450cb95a1e 91