3 // HX711.DOUT - pin #A2
4 // HX711.PD_SCK - pin #A1
6 HX711 scale(A2, A1); // parameter "gain" is ommited; the default value 128 is used by the library
8 #include <LiquidCrystal.h>
9 LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // rs enable d0-d3
16 Serial.println("HX711 Demo");
18 Serial.println("Before setting up the scale:");
19 Serial.print("read: \t\t");
20 Serial.println(scale.read()); // print a raw reading from the ADC
22 Serial.print("read average: \t\t");
23 Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
25 Serial.print("get value: \t\t");
26 Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight (not set yet)
28 Serial.print("get units: \t\t");
29 Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight (not set) divided
30 // by the SCALE parameter (not set yet)
32 scale.set_scale(465.f); // this value is obtained by calibrating the scale with known weights; see the README for details
33 scale.tare(); // reset the scale to 0
35 Serial.println("After setting up the scale:");
37 Serial.print("read: \t\t");
38 Serial.println(scale.read()); // print a raw reading from the ADC
40 Serial.print("read average: \t\t");
41 Serial.println(scale.read_average(20)); // print the average of 20 readings from the ADC
43 Serial.print("get value: \t\t");
44 Serial.println(scale.get_value(5)); // print the average of 5 readings from the ADC minus the tare weight, set with tare()
46 Serial.print("get units: \t\t");
47 Serial.println(scale.get_units(5), 1); // print the average of 5 readings from the ADC minus tare weight, divided
48 // by the SCALE parameter set with set_scale
50 Serial.println("Readings:");
55 #define g_size g_bucket*3
56 float g_history[g_size];
61 float g = scale.get_units();
65 lcd.setCursor(0,0); // col,row
70 g_history[g_pos++] = g; // insert into circular buffer
74 for(int i=1; i<g_size; i++) {
75 int pos = ( g_pos + i ) % g_size;
76 sum += g_history[pos];
77 if ( i % g_bucket == 0) {
87 int key = analogRead(0);
98 } else if ( key > 800 ) {
103 uint32_t adc = scale.read();
111 // scale.power_down(); // put the ADC in sleep mode