1#include <Wire.h>
2#include <STM32_TM1637.h>
3STM32_TM1637 tm(2,3);
4
5#define ADDR 0x48
6#define U33 3.342
7int n=3;
8float r,u,n_u=0.256,r0;
9 long dig_sum,dig;
10 int value,f;
11
12void setup() {
13 Serial.begin(9600);
14 tm.brig(7);
15 Wire.begin();
16 pinMode(4,INPUT_PULLUP);
17}
18
19void loop() {
20 r = ((100.00*u)/(U33-u))-r0;
21 if(digitalRead(4)==LOW&&r<0.1){r0=((100.00*u)/(U33-u));delay(200);}
22
23 for(int i=0;i<10;i++){
24 read_u();
25 dig_sum = dig_sum+value;delay(10);}
26
27read_u();if(value>0x7FFF-0xF&&n==1){delay(10);n=0;n_u=2.048;}
28read_u();if(value>0x7FFF-0xF&&n==2){delay(10);n=1;n_u=1.024;}
29read_u();if(value>0x7FFF-0xF&&n==3){delay(10);n=2;n_u=0.512;}
30read_u();if(value<16380&&n==0){delay(10);n=1;n_u=1.024;}
31read_u();if(value<16380&&n==1){delay(10);n=2;n_u=0.512;}
32read_u();if(value<16380&&n==2){delay(10);n=3;n_u=0.256;}
33
34 dig = dig_sum/10;dig_sum=0;
35 u = dig*n_u/0x7FFF;
36
37 if(r<10){tm.print_float(r,3 ,0,0,0,0);}
38 if(r>=10&&r<100){tm.print_float(r,2 ,0,0,0,0);}
39 if(r>=100&&r<=150){tm.print_float(r,1 ,0,0,0,0);}
40 if(r>150){tm.print_float(r,0 ,0b01000000,0b01000000,0b01000000,0b01000000);}
41
42 Serial.println(r0,5);
43 }
44
45float read_u(){
46 Wire.beginTransmission(ADDR);
47 Wire.write (0b10001100+n);
48 Wire.endTransmission();
49 Wire.requestFrom(ADDR,2);
50 while(Wire.available()<2);
51 value = (Wire.read()<<8) + (Wire.read());
52 }
bcrfan
8 months ago
Great Project. The currently available (in 2024) 4 digit display (from AliXpress) requires the TM1637.h library and will not light up with the STM32_TM1637 required library. The code needs changing to use the TM1637.h library which unfortunately looks more involved than I am capable of. Hopefully the author can update the code to use the newer library?