1#include <U8g2lib.h>
2#include <Capacitor.h>
3
4U8G2_ST7565_ERC12864_1_4W_SW_SPI u8g2 ( U8G2_R0, 13 , 11 , 10 , 9 , 8 ) ;
5
6Capacitor cap1(7,A2);
7
8int X1,C;
9byte f_ic, xp;
10char R1_str[3];
11char R_str[4];
12float tau1;
13unsigned long T1, T2, tau;
14
15void setup() {
16 Serial.begin(9600);
17 u8g2.begin();
18 u8g2.setContrast(35);
19}
20
21
22 void loop() {
23
24
25 Pomiar_C();
26}
27
28
29void Pomiar_C(){
30 Cyfry();
31 char C_str[4];
32 sprintf(C_str,"%d", X1);
33 u8g2.firstPage();
34 do {
35
36 u8g2.drawFrame(0,0,128,64);
37 u8g2.drawRFrame(2,2,124,60,3);
38
39 u8g2.setFont(u8g2_font_10x20_tr);
40 u8g2.drawStr(20, 18, "Capacity:");
41 if (f_ic > 6) {
42 u8g2.setFont(u8g2_font_fub25_t_symbol);
43 u8g2.drawGlyph(80,52,956);
44 }
45 u8g2.setFont(u8g2_font_fub25_tr);
46 u8g2.drawStr(xp, 52, C_str);
47 if (f_ic < 7) {u8g2.drawStr(76, 52, "n");}
48 if (f_ic < 4) {u8g2.drawStr(76, 52, "p");}
49 u8g2.drawStr(100, 52, "F");
50 if (f_ic == 1 or f_ic == 4 or f_ic == 7) {
51 u8g2.drawStr(28, 52, ".");
52 u8g2.drawStr(40, 52, R1_str);
53 }
54 } while ( u8g2.nextPage() );
55 delay(500);
56}
57
58void Cyfry(){
59
60
61
62
63 tau1 = cap1.Measure();
64
65 if (tau1 >= 1 && tau1 <10) {
66 X1 = tau1;
67 int X2 = 10 * (tau1 - X1);
68 sprintf(R1_str,"%d", X2);
69 f_ic = 1;
70 xp = 10;
71 }
72 if (tau1 >= 10 && tau1 <100) {
73 X1 = tau1;
74 f_ic = 2;
75 xp = 32;
76 }
77 if (tau1 >= 100 && tau1 <1000) {
78 X1 = tau1;
79 f_ic = 3;
80 xp = 10;
81 }
82 if (tau1/1000 >= 1 && tau1/1000 <10) {
83 X1 = int(tau1/1000);
84 f_ic = 4;
85 xp = 10;
86 int X2 = 10 * (tau1/1000 - X1);
87 sprintf(R1_str,"%d", X2);
88 }
89 if (tau1/10000 >= 1 && tau1/10000 <10) {
90 X1 = int(tau1/1000);
91 f_ic = 5;
92 xp = 32;
93 }
94 if (tau1/100000 >= 1 && tau1/100000 <10) {
95 X1 = int(tau1/1000);
96 f_ic = 6;
97 xp = 10;
98 }
99 if (tau1/1000000 >= 1 && tau1/1000000 <10) {
100 X1 = int(tau1/1000000);
101 f_ic = 7;
102 xp = 10;
103
104 int X2 = 10 * (tau1/1000000 - X1);
105 sprintf(R1_str,"%d", X2);
106 }
107 if (tau1/10000000 >= 1 && tau1/10000000 <10) {
108 X1 = int(tau1/1000000);
109 f_ic = 8;
110 xp = 30;
111 }
112}
nante
4 months ago
Or with a 128x64 ssd1306 oled display