Back to Parent

// This #include statement was automatically added by the Particle IDE.
#include <HX711ADC.h>


HX711ADC scale(A1, A0);		// parameter "gain" is ommited; the default value 128 is used by the library
float milk_level=0.0f;
void setup() {
 
    Serial.begin(38400);
    Serial.println("HX711 Demo");
    scale.begin();
 
    
    Serial.println("Before setting up the scale:");
      Serial.print("read: \t\t");
      Serial.println(scale.read());			// print a raw reading from the ADC
    
      Serial.print("read average: \t\t");
      Serial.println(scale.read_average(20));  	// print the average of 20 readings from the ADC
    
      Serial.print("get value: \t\t");
      Serial.println(scale.get_value(5));		// print the average of 5 readings from the ADC minus the tare weight (not set yet)
    
      Serial.print("get units: \t\t");
      Serial.println(scale.get_units(5), 1);	// print the average of 5 readings from the ADC minus tare weight (not set) divided 
    						// by the SCALE parameter (not set yet)  
    
      scale.set_scale(456.f);                      // this value is obtained by calibrating the scale with known weights; see the README for details
      scale.tare(10);				        // reset the scale to 0
    
      Serial.println("After setting up the scale:");
    
      Serial.print("read: \t\t");
      Serial.println(scale.read());                 // print a raw reading from the ADC
    
      Serial.print("read average: \t\t");
      Serial.println(scale.read_average(20));       // print the average of 20 readings from the ADC
    
      Serial.print("get value: \t\t");
      Serial.println(scale.get_value(5));		// print the average of 5 readings from the ADC minus the tare weight, set with tare()
    
      Serial.print("get units: \t\t");
      Serial.println(scale.get_units(5), 1);        // print the average of 5 readings from the ADC minus tare weight, divided 
    						// by the SCALE parameter set with set_scale
    
      Serial.println("Readings:");
}

void loop() {
  milk_level=scale.get_units();
  Serial.print("one reading:\t");
  Serial.print(milk_level, 1);
  Serial.print("\n");
//   Serial.println(scale.get_units(10), 1);
   
    
    Particle.publish("DIOT/CP2/Milkbox/Weight",String(milk_level));

  scale.power_down();			        // put the ADC in sleep mode
  delay(1500);
  scale.power_up();
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0