Eugene Mwangi
/
mbed_blinky
A test program for hx711 built for mbed Os framework.
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "Hx711.h" 00003 00004 00005 00006 float calibration_factor = -1.0f; // this calibration factor is adjusted according to my load cell 00007 int32_t units_raw; 00008 float units; 00009 float ounces; 00010 int offset = 0; 00011 00012 Hx711 scale(D4, D5); 00013 00014 //void delay(int delay){ 00015 // for(int i=0; i<delay;i++) 00016 //} 00017 00018 int main() { 00019 printf("HX711 calibration sketch\n"); 00020 printf("Remove all weight from scale\n"); 00021 printf("After readings begin, place known weight on scale\n"); 00022 printf("Press + or a to increase calibration factor\n"); 00023 printf("Press - or z to decrease calibration factor\n"); 00024 00025 offset = (int)scale.read(); 00026 scale.set_offset(offset); 00027 printf("Reading: %d \n",offset); 00028 scale.set_scale(calibration_factor); 00029 while(1) { 00030 wait_ms(1000); 00031 00032 units_raw = scale.readRaw(); 00033 units = scale.read(); 00034 if (units < 0) 00035 { 00036 units = 0.00; 00037 } 00038 // ounces = units * 0.035274f; 00039 printf("Raw reading: %d grams. \n",units_raw); 00040 printf("Actual reading: %f grams. \n",units); 00041 // printf("Calibration_factor: %f\n",calibration_factor); 00042 wait_ms(10000); 00043 } 00044 } 00045 00046 00047 00048 00049 00050 00051
Generated on Mon Jul 18 2022 03:40:14 by 1.7.2