Celda de Carga HX711

Dependencies:   HX711 TextLCD mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "HX711.h"
00003 #include "TextLCD.h" 
00004 
00005 DigitalOut led(LED_BLUE);
00006 HX711 scale(PTC9, PTC8);
00007 
00008 Serial rs232(USBTX, USBRX);    // USB Serial Terminal
00009 TextLCD lcd(PTE20,PTE21,PTE22,PTE23,PTE29,PTE30, TextLCD::LCD16x2); // Rs, E, d4, d5, d6, d7 
00010 
00011 float calibration_factor = 1000; //Ajustar este valor para calibrar el peso exacto
00012 int averageSamples = 100;
00013 
00014 int main(void)
00015 {
00016      
00017     scale.setScale(0);
00018     scale.tare(); //Reset the scale to 0
00019     
00020     long zero_factor = scale.averageValue(averageSamples); // Saca promedio de varias lecturas para estabilizar la medida
00021      
00022     while (true) {
00023         scale.setScale(calibration_factor); 
00024         float weight = scale.getGram();
00025         rs232.printf("Peso: %.2f\n", weight);
00026         lcd.locate(0,0);
00027         lcd.printf("Peso: %.2f Grms", weight);
00028         led = !led; // toggle led
00029         wait(0.2f);
00030     }
00031 }