1#include <U8g2lib.h>
2#include <SPI.h>
3
4#define GAIN 100
5#define STEP 8
6#define LOW_SOUND 50
7#define MAX_SOUND 600
8
9
10U8G2_GP1287AI_256X50_1_4W_SW_SPI u8g2(U8G2_R0, 13, 11, 10, 9, 8);
11
12 int strela=-36;
13 int hMeter = 64;
14 int vMeter = 85;
15 int rMeter = 77;
16 int ur,urr,x;
17
18 int strelax =-36;
19 int hMeterx = 194;
20 int vMeterx = 85;
21 int rMeterx = 77;
22 int urx,urrx,xx;
23
24void setup(void) {
25 u8g2.begin();
26 u8g2.setContrast(25);
27 u8g2.enableUTF8Print();
28 u8g2.setFont(u8g2_font_4x6_tf);
29 analogReference(INTERNAL);
30 pinMode(A2,INPUT);
31 pinMode(A0,INPUT);
32}
33
34void loop (){
35
36 strela = map(log(analogRead(A2))*GAIN, LOW_SOUND,MAX_SOUND, -36,36);
37 strela = constrain(strela, -36, 36);
38 urr = strela;if(urr<ur){ur=ur-STEP;}else{ur = strela;}
39
40
41 strelax = map(log(analogRead(A0))*GAIN, LOW_SOUND,MAX_SOUND, -36,36);
42 strelax = constrain(strelax, -36, 36);
43 urrx = strelax;if(urrx<urx){urx=urx-STEP;}else{urx = strelax;}
44
45
46 u8g2.firstPage();
47 do {
48 u8g2.drawFrame(0,0,256,50);
49 u8g2.drawRFrame(130,2,124,46,3);
50 u8g2.drawRFrame(2,2,127,46,3);
51 u8g2.drawLine(20, 15, 70, 15);
52 u8g2.drawLine(150, 15, 200, 15);
53 u8g2.drawLine(73, 15, 108, 15);
54 u8g2.drawLine(203, 15, 238, 15);
55 u8g2.drawLine(73, 14, 108, 14);
56 u8g2.drawLine(203, 14, 238, 14);
57 u8g2.drawLine(15, 17, 70, 17);
58 u8g2.drawLine(145, 17, 200, 17);
59
60 byte b1_2[10]{20,57,42,33,64,91,50,70,77,104};
61 byte c1_2[10]{12,14,14,12,14,12,12,12,12,12};
62 for(int i=0;i<10;i++){u8g2.drawLine(b1_2[i], 15, b1_2[i], c1_2[i]);}
63 byte b3[5]{15,29,43,57,70};
64 for(int i=0;i<5;i++){u8g2.drawLine(b3[i], 17, b3[i], 20);}
65
66
67 byte b1x_2[10]{150,187,172,163,194,221,180,200,207,234};
68 byte c1x_2[10]{12,14,14,12,14,12,12,12,12,12};
69 for(int i=0;i<10;i++){u8g2.drawLine(b1x_2[i], 15, b1x_2[i], c1x_2[i]);}
70 byte b3x[5]{145,159,173,187,200};
71 for(int i=0;i<5;i++){u8g2.drawLine(b3x[i], 17, b3x[i], 20);}
72
73
74 u8g2.setCursor(17, 10); u8g2.print(F("20 10 3 0 1"));
75 u8g2.setCursor(147, 10); u8g2.print(F("20 10 3 0 1"));
76 u8g2.setCursor(14, 28); u8g2.print(F("0 25"));
77 u8g2.setCursor(144, 28); u8g2.print(F("0 25"));
78 u8g2.setCursor(40, 28); u8g2.print(F("50"));
79 u8g2.setCursor(170, 28); u8g2.print(F("50"));
80 u8g2.setCursor(55, 28);u8g2.print(F("75"));
81 u8g2.setCursor(185, 28);u8g2.print(F("75"));
82 u8g2.setCursor(68, 28);u8g2.print(F("100"));
83 u8g2.setCursor(198, 28);u8g2.print(F("100"));
84 u8g2.setCursor(90, 10);u8g2.print(F("2"));
85 u8g2.setCursor(220, 10);u8g2.print(F("2"));
86 u8g2.setCursor(103, 10);u8g2.print(F("3"));
87 u8g2.setCursor(233, 10);u8g2.print(F("3"));
88
89 u8g2.setCursor(14, 40); u8g2.print(F("-"));
90 u8g2.setCursor(104, 40);u8g2.print(F("+"));
91 u8g2.setCursor(44, 40);u8g2.print(F("VU meter"));
92
93 u8g2.setCursor(90, 40);u8g2.print(F("L"));
94 u8g2.drawFrame(88,33,7,9);
95
96 u8g2.setCursor(144, 40); u8g2.print(F("-"));
97 u8g2.setCursor(234, 40);u8g2.print(F("+"));
98 u8g2.setCursor(174, 40);u8g2.print(F("VU meter"));
99
100 u8g2.setCursor(220, 40);u8g2.print(F("R"));
101 u8g2.drawFrame(218,33,7,9);
102
103 int a1 = (hMeter + (sin(ur / 57.296) * rMeter));
104 int a2 = (vMeter - (cos(ur / 57.296) * rMeter));
105 u8g2.drawLine(a1, a2, hMeter, vMeter);
106
107
108
109 int a1x = (hMeterx + (sin(urx / 57.296) * rMeterx));
110 int a2x = (vMeterx - (cos(urx / 57.296) * rMeterx));
111 u8g2.drawLine(a1x, a2x, hMeterx, vMeterx);
112
113
114
115
116 } while ( u8g2.nextPage() );
117
118}