5 // HX711.DOUT - pin #A2
6 // HX711.PD_SCK - pin #A1
8 HX711 scale(A2, A1); // parameter "gain" is ommited; the default value 128 is used by the library
10 #include <LiquidCrystal.h>
11 LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // rs enable d0-d3
18 Serial.println("HX711");
20 Serial.println("Before setting up the scale:");
21 Serial.print("read: \t\t");
22 Serial.println(scale.read()); // print a raw reading from the ADC
24 Serial.print("read average: \t\t");
25 Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
27 Serial.print("get value: \t\t");
28 Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet)
30 Serial.print("get units: \t\t");
31 Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided
32 // by the SCALE parameter (not set yet)
33 scale.set_scale(465.f); // this value is obtained by calibrating the scale with known weights; see the README for details
34 scale.tare(); // reset the scale to 0
36 Serial.println("After setting up the scale:");
38 Serial.print("read: \t\t");
39 Serial.println(scale.read()); // print a raw reading from the ADC
41 Serial.print("read average: \t\t");
42 Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
44 Serial.print("get value: \t\t");
45 Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare()
47 Serial.print("get units: \t\t");
48 Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided
49 // by the SCALE parameter set with set_scale
51 Serial.println("Readings:");
56 #define g_size g_bucket*3
57 float g_history[g_size];
64 uint32_t adc = scale.read();
71 float g = scale.get_units();
74 lcd.setCursor(0,0); // col,row
79 g_history[g_pos++] = g; // insert into circular buffer
83 for(int i=1; i<g_size; i++) {
84 int pos = ( g_pos + i ) % g_size;
85 sum += g_history[pos];
86 if ( i % g_bucket == 0) {
96 int key = analogRead(0);
106 } else if ( key > 800 ) {
112 // scale.power_down(); // put the ADC in sleep mode