-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBasicprogram
More file actions
73 lines (48 loc) · 1.2 KB
/
Basicprogram
File metadata and controls
73 lines (48 loc) · 1.2 KB
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
#include "SD.h"
#define SD_ChipSelectPin 53
#include "TMRpcm.h"
#include "SPI.h"
// use more minutes sound to avoid tmrpcm.loop breaks
TMRpcm tmrpcm;
int vol=0 , basefreq = 16000,basevol = 1;
// double timefactor;
byte btt;
char filename[] = "6.wav";
double x=0,y=0,z=0;
void setup(){
tmrpcm.speakerPin = 11;
tmrpcm.speakerPin2 = 12;
btt = B01100000;
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
return;
}
tmrpcm.SAMPLE_RATE = basefreq;
tmrpcm.quality(1);
tmrpcm.loop(1);
tmrpcm.setVolume(basevol);
tmrpcm.play(filename);
}
void loop(){
// reading frequency value from serial
z= Serial.parseFloat();
if(z!=0&&z<1001){
// map function ,takes value between 0 and 1000 and adjust freq and sound accordingly
x = map(z,0,1000,basefreq,45000);
vol = map(z,0,1000,basevol,5);
tmrpcm.setVolume(vol);
// setting sample rate
tmrpcm.SAMPLE_RATE = x;
// setting resolution
if(bitRead(btt,6)){tmrpcm.resolution = 10 * (800000/tmrpcm.SAMPLE_RATE);}
else{ tmrpcm.resolution = 10 * (1600000/tmrpcm.SAMPLE_RATE);
}
noInterrupts();
tmrpcm.timerSt();
//timefactor = y/x;
interrupts();
// currentval/newval
// timefactor = x/(32000.00/time);
}
}