Scientific task box V1
Dependents: Scientific_RTOS Scientific_RTOS
Diff: BOX.cpp
- Revision:
- 0:01deb85101c9
- Child:
- 2:f8120bb54b69
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/BOX.cpp Mon May 13 13:55:19 2019 +0000 @@ -0,0 +1,53 @@ +#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); +}