jun takahashi
/
loadcell_outF
ACM txt out
Diff: main.cpp
- Revision:
- 0:2d84c250f000
diff -r 000000000000 -r 2d84c250f000 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Feb 28 03:36:09 2019 +0000 @@ -0,0 +1,49 @@ +#include "mbed.h" +#include "HX711.h" + +DigitalOut gpo(D0); +//DigitalOut led(LED_BLUE); +DigitalOut led(LED1); + +HX711 scale(p6,p7); + +AnalogIn scaleRaw(A3); +Serial pc(USBTX, USBRX); // USB Serial Terminal +float calibration_factor = 1.000; //-7050 worked for my 440lb max scale setup +int averageSamples = 100; + +LocalFileSystem local("local"); // Create the local filesystem under the name "local" + +int i; + +int main(void) +{ + // pc.printf("Starting Scale"); + // pc.printf("HX711 calibration sketch"); + // pc.printf("Remove all weight from scale"); + // pc.printf("After readings begin, place known weight on scale"); + // pc.printf("Press + or a to increase calibration factor"); + // pc.printf("Press - or z to decrease calibration factor"); + + + scale.setScale(0); + scale.tare(); //Reset the scale to 0 + + long zero_factor = scale.averageValue(averageSamples); //Get a baseline reading + // pc.printf("Zero factor: %.4f\n" , zero_factor); //This can be used to remove the need to tare the scale. Useful in permanent scale projects. + + //while (true) { + scale.setScale(calibration_factor); //Adjust to this calibration factor + float weight = scale.getGram(); + // pc.printf(" %5.3e\n", weight); + + FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing + fprintf(fp, " %5.3e\n", weight); + fclose(fp); + + + gpo = !gpo; // toggle pin + led = !led; // toggle led + wait(0.2f); + // } +} \ No newline at end of file