-
Notifications
You must be signed in to change notification settings - Fork 1
/
Smeter2.h
75 lines (54 loc) · 1.56 KB
/
Smeter2.h
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
74
75
// soft AGC and S meter display by Loftur E. Jónasson TF3LJ/VE2LJX 6/14
//
//extern Adafruit_QDTech tft;
//extern Adafruit_S6D02A1 tft;
extern ER_TFT0784_t3 tft;
extern AudioAnalyzePeak_F32 peak; // Measure Audio Peak for S meter
float new_sample; // Raw signal strength (max per 1ms)
float old_sample=0.0;
float s_old=0.0;
float uv, dbuv, s;// microvolts, db-microvolts, s-units
void sMeter()
{
if (peak.available())
{
new_sample = peak.read();
old_sample = (old_sample + new_sample)/2;
// Serial.println(old_sample*3000,7);
}
int barlength =(int)(old_sample*3000);
if(barlength>300)
{
barlength=300;
}
tft.fillRect(125, 40, 300 , 15,BLACK);
tft.fillRect(125, 42, barlength, 13,GREEN);
// tft.fillRect(20, 65, 90, 20,BLACK);
// tft.setFont(Arial_14);
// tft.setCursor(20,70);
// tft.print((int)(old_sample*3000));
}
void sMeter2()
{
if (peak.available())
{
new_sample = peak.read();
// Calculate S units. 50uV = S9
uv = new_sample*1000; // microvolts, roughly calibrated
dbuv = 20.0*log10(uv);
s = 1.0 + (14.0 + dbuv)/6.0;
if (s <0.0) s=0.0;
if (s>9.0)
{
dbuv = dbuv - 34.0;
s = 9.0;
}
else dbuv = 0;
// Print S units
tft.fillRect(125, 30, 140, 5,GREEN);
tft.fillRect(20, 65, 90, 20,BLACK);
tft.setFont(Arial_14);
tft.setCursor(20,70);
tft.print(dbuv,5);
}
}