Eugene Mwangi
/
mbed_blinky
A test program for hx711 built for mbed Os framework.
Diff: main.cpp
- Revision:
- 25:611277904537
- Parent:
- 24:7f14b70fc9ef
--- a/main.cpp Mon Apr 08 11:03:25 2019 +0100 +++ b/main.cpp Tue Jun 25 15:16:15 2019 +0000 @@ -1,12 +1,51 @@ #include "mbed.h" +#include "Hx711.h" + + -DigitalOut myled(LED1); +float calibration_factor = -1.0f; // this calibration factor is adjusted according to my load cell +int32_t units_raw; +float units; +float ounces; +int offset = 0; + +Hx711 scale(D4, D5); + +//void delay(int delay){ +// for(int i=0; i<delay;i++) +//} int main() { + printf("HX711 calibration sketch\n"); + printf("Remove all weight from scale\n"); + printf("After readings begin, place known weight on scale\n"); + printf("Press + or a to increase calibration factor\n"); + printf("Press - or z to decrease calibration factor\n"); + + offset = (int)scale.read(); + scale.set_offset(offset); + printf("Reading: %d \n",offset); + scale.set_scale(calibration_factor); while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); + wait_ms(1000); + + units_raw = scale.readRaw(); + units = scale.read(); + if (units < 0) + { + units = 0.00; + } +// ounces = units * 0.035274f; + printf("Raw reading: %d grams. \n",units_raw); + printf("Actual reading: %f grams. \n",units); +// printf("Calibration_factor: %f\n",calibration_factor); + wait_ms(10000); } } + + + + + + + \ No newline at end of file