Skip to content

Commit 1596cf9

Browse files
authored
Create Basicprogram
1 parent 7ab4dc5 commit 1596cf9

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

Basicprogram

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
#include "SD.h"
3+
#define SD_ChipSelectPin 53
4+
#include "TMRpcm.h"
5+
#include "SPI.h"
6+
7+
// use more minutes sound to avoid tmrpcm.loop breaks
8+
TMRpcm tmrpcm;
9+
10+
int vol=0 , basefreq = 16000,basevol = 1;
11+
// double timefactor;
12+
byte btt;
13+
char filename[] = "6.wav";
14+
double x=0,y=0,z=0;
15+
16+
17+
18+
19+
void setup(){
20+
21+
tmrpcm.speakerPin = 11;
22+
tmrpcm.speakerPin2 = 12;
23+
btt = B01100000;
24+
Serial.begin(9600);
25+
if (!SD.begin(SD_ChipSelectPin)) {
26+
Serial.println("SD fail");
27+
return;
28+
}
29+
30+
31+
tmrpcm.SAMPLE_RATE = basefreq;
32+
tmrpcm.quality(1);
33+
tmrpcm.loop(1);
34+
tmrpcm.setVolume(basevol);
35+
tmrpcm.play(filename);
36+
37+
38+
39+
}
40+
41+
void loop(){
42+
// reading frequency value from serial
43+
z= Serial.parseFloat();
44+
45+
46+
47+
if(z!=0&&z<1001){
48+
// map function ,takes value between 0 and 1000 and adjust freq and sound accordingly
49+
x = map(z,0,1000,basefreq,45000);
50+
vol = map(z,0,1000,basevol,5);
51+
tmrpcm.setVolume(vol);
52+
53+
54+
// setting sample rate
55+
tmrpcm.SAMPLE_RATE = x;
56+
// setting resolution
57+
if(bitRead(btt,6)){tmrpcm.resolution = 10 * (800000/tmrpcm.SAMPLE_RATE);}
58+
else{ tmrpcm.resolution = 10 * (1600000/tmrpcm.SAMPLE_RATE);
59+
}
60+
61+
noInterrupts();
62+
tmrpcm.timerSt();
63+
//timefactor = y/x;
64+
interrupts();
65+
// currentval/newval
66+
// timefactor = x/(32000.00/time);
67+
68+
69+
70+
71+
}
72+
73+
}

0 commit comments

Comments
 (0)