Scientific task box V1

Dependencies:   HX711 DS1820

Dependents:   Scientific_RTOS Scientific_RTOS

BOX.cpp

Committer:
Alessio_Zaino
Date:
2019-05-13
Revision:
0:01deb85101c9
Child:
2:f8120bb54b69

File content as of revision 0:01deb85101c9:

#include "BOX.h"

BOX::BOX (PinName pinCLK_HX711, PinName pinDAT_HX711, PinName pin_temp, PinName pin_cond, int HX711_coefficent):therm(pin_temp, DS18B20::RES_12_BIT),balance(pinDAT_HX711, pinCLK_HX711)
{
  _pinCLK = pinCLK_HX711;
  _pinDAT = pinDAT_HX711;
  _pintemp = pin_temp;
  _pincond = pin_cond;
  _coefficent = HX711_coefficent;
  
  
}

//BOX::~BOX(){}

float BOX::get_temp()
{
  float temperature;
  _tmp = 0;
  for (int i = 0; i < 20; i++)
  {
    _tmp = therm.GetTemperature();
    temperature = temperature + _tmp;
  }
  return temperature / 20;
}

int BOX::get_resistance()
{
  AnalogIn cond_value(_pincond);                // reads voltage on the conductimeter pin.
  float meas_v;
  float current;
  float resistance;
  _tmp = 0;
  for(int i = 0; i < 20; i++)
  {
    meas_v = cond_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range)
    current = (1 - meas_v) / (2000000); // kvl and V/R to get current
    _tmp = (meas_v / current);    // Ohm law gives us the soil resistence
    resistance = resistance + _tmp;
  }
  return (int) (resistance / 20);
}

void BOX::tare(unsigned char times)
{
  balance.setTare(balance.averageValue(times));
}

int BOX::get_weight()
{
  return (int) (balance.getGram() / _coefficent);
}