Library to read out HX711 24-Bit Analog-to-Digital Converter (ADC) for Weigh Scales by AVIA Semiconductor. Tested with K22F with SCK pint at D13 and DT pin at D12
Diff: Hx711.h
- Revision:
- 2:f118f8c456a4
- Parent:
- 1:197ef68ad6de
- Child:
- 3:9bbfb7f8c751
diff -r 197ef68ad6de -r f118f8c456a4 Hx711.h --- a/Hx711.h Thu Jun 16 07:31:43 2016 +0000 +++ b/Hx711.h Thu Jun 23 09:59:29 2016 +0000 @@ -62,14 +62,23 @@ * Waits for the chip to be ready and returns a raw int reading * @return int sensor output value */ - int readRaw(); + uint32_t readRaw(); /** * Obtain offset and scaled sensor output; i.e. a real value * @return float */ float read() { - return ((float)(readRaw() - get_offset())) * get_scale(); + convert_to_real(readRaw()); + } + + /** + * Convert integer value from chip to offset and scaled real value + * @param val integer value + * @return (val - get_offset()) * get_scale() + */ + float convert_to_real(int val) { + return ((float)(val - get_offset())) * get_scale(); } /** @@ -108,7 +117,7 @@ * Set the scale factor * @param scale desired scale */ - void set_scale(float scale = 1.f) { + void set_scale(float scale = 1.0f) { scale_ = scale; };