-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSoundPlayer.cpp
77 lines (54 loc) · 1.12 KB
/
SoundPlayer.cpp
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
#include "Arduino.h"
#include <NewTone.h>
#include "SoundPlayer.h"
SoundPlayer::SoundPlayer(byte speakerPin)
{
_speakerPin = speakerPin;
}
void SoundPlayer::playGun()
{
noise(NOTE_E6, 100, 20);
noise(NOTE_G6, 100, 50);
}
void SoundPlayer::playCoin()
{
delay(100);
NewTone(_speakerPin, NOTE_E6, 250);
delay(100);
noNewTone(_speakerPin);
}
void SoundPlayer::play1UP()
{
NewTone(_speakerPin, NOTE_E6, 60);
//delay(85);
NewTone(_speakerPin, NOTE_G6, 60);
//delay(85);
NewTone(_speakerPin, NOTE_E7, 60);
//delay(85);
NewTone(_speakerPin, NOTE_C7, 60);
//delay(85);
NewTone(_speakerPin, NOTE_D7, 60);
//delay(85);
NewTone(_speakerPin, NOTE_G7, 60);
//delay(85);
noNewTone(_speakerPin);
}
void SoundPlayer::explosion()
{
noise(700, 40, 20);
noise(450, 30, 15);
noise(300, 20, 10);
noise(250, 20, 10);
noise(120, 30, 50);
noise(100, 40, 50);
}
void SoundPlayer::noise(int freq, int var, int duration)
{
int low = freq - var;
int high = freq + var;
unsigned long time = millis();
while (millis() - time <= duration) {
NewTone(_speakerPin, random(low, high));
}
noNewTone(_speakerPin);
}