1

Тема: Миллиомметр на ADS1110

http://rcl-radio.ru/?p=100859

#include <Wire.h>
#include <STM32_TM1637.h>                // http://rcl-radio.ru/wp-content/uploads/2020/02/STM32_TM1637_V1_3.zip
STM32_TM1637 tm(2,3);// CLK, DIO

#define ADDR 0x48
#define U33 3.342
int n=3;
float r,u,n_u=0.256,r0;
  long dig_sum,dig;
  int value,f;
  
void setup() {
  Serial.begin(9600);
  tm.brig(7); // ЯРКОСТЬ 0...7
  Wire.begin();
  pinMode(4,INPUT_PULLUP);// null
}

void loop() {
  r = ((100.00*u)/(U33-u))-r0;
  if(digitalRead(4)==LOW&&r<0.1){r0=((100.00*u)/(U33-u));delay(200);}

  for(int i=0;i<10;i++){
  read_u();
  dig_sum = dig_sum+value;delay(10);}

read_u();if(value>0x7FFF-0xF&&n==1){delay(10);n=0;n_u=2.048;}
read_u();if(value>0x7FFF-0xF&&n==2){delay(10);n=1;n_u=1.024;}
read_u();if(value>0x7FFF-0xF&&n==3){delay(10);n=2;n_u=0.512;}
read_u();if(value<16380&&n==0){delay(10);n=1;n_u=1.024;}
read_u();if(value<16380&&n==1){delay(10);n=2;n_u=0.512;}
read_u();if(value<16380&&n==2){delay(10);n=3;n_u=0.256;}
 
  dig = dig_sum/10;dig_sum=0;
  u = dig*n_u/0x7FFF;

 if(r<10){tm.print_float(r,3 ,0,0,0,0);}
 if(r>=10&&r<100){tm.print_float(r,2 ,0,0,0,0);}
 if(r>=100&&r<=150){tm.print_float(r,1 ,0,0,0,0);}
 if(r>150){tm.print_float(r,0 ,0b01000000,0b01000000,0b01000000,0b01000000);}
 
 Serial.println(r0,5);
  }

float read_u(){
  Wire.beginTransmission(ADDR);
  Wire.write (0b10001100+n);
  Wire.endTransmission();
  Wire.requestFrom(ADDR,2);
  while(Wire.available()<2);
  value = (Wire.read()<<8) + (Wire.read());
  }