I need help adding a for statement in a section of code. When the section reaches "Collecting Data" in the loop function I want the load cell to update the weight value 100 time assuming 10 samples/sec before the "Complete" status starts. I believe it would be something like this for (int i=0; i <= 100; i++){ where do I add this in the code.
Also how do I put "grams" at the end of every value the load cell reads.
int ButtonValue = 0;
int Button = 3;
int LEDRED = 4;
int LEDORANGE = 2;
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <HX711_ADC.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#if defined(ESP8266)|| defined(ESP32) || defined(AVR)
#include <EEPROM.h>
#endif
const int HX711_dout = 9; //mcu > HX711 dout pin
const int HX711_sck = 8; //mcu > HX711 sck pin
HX711_ADC LoadCell(HX711_dout, HX711_sck);
const int calVal_eepromAdress = 0;
unsigned long t = 0;
void setup() {
pinMode(Button, INPUT);
pinMode (LEDRED, OUTPUT);
pinMode (LEDORANGE, OUTPUT);
pinMode(10,OUTPUT);
Serial.begin(9600); delay(10);
Serial.println();
Serial.println("Starting");
lcd.init();
lcd.backlight();
lcd.setCursor(0,0);
lcd.print("Starting");
LoadCell.begin();
float calibrationValue; // calibration value (see example file "Calibration.ino")
calibrationValue = 696.0; // uncomment this if you want to set the calibration value in the sketch
#if defined(ESP8266)|| defined(ESP32)
//EEPROM.begin(512); // uncomment this if you use ESP8266/ESP32 and want to fetch the calibration value from eeprom
#endif
EEPROM.get(calVal_eepromAdress, calibrationValue); // uncomment this if you want to fetch the calibration value from eeprom
unsigned long stabilizingtime = 2000; // preciscion right after power-up can be improved by adding a few seconds of stabilizing time
boolean _tare = true; //set this to false if you don't want tare to be performed in the next step
LoadCell.start(stabilizingtime, _tare);
if (LoadCell.getTareTimeoutFlag()) {
Serial.println("Timeout, check MCU>HX711 wiring and pin designations");
while (1);
}
else {
LoadCell.setCalFactor(calibrationValue); // set calibration value (float)
Serial.println("Stand By");
lcd.clear();
lcd.print("Stand By");
}
}
void loop() {
ButtonValue = digitalRead(Button);
if(ButtonValue !=0) {
digitalWrite(LEDRED, HIGH);
lcd.setCursor(0,0);
lcd.print("Timer Activated");
Serial.println("Timer Activated");
lcd.setCursor(0,1);
lcd.print("Stand Back!");
Serial.println("Stand Back!");
delay(10000);
lcd.clear();
digitalWrite(LEDRED, LOW);
digitalWrite(LEDORANGE, HIGH);
digitalWrite(10,HIGH);
lcd.setCursor(0,0);
lcd.print("Collecting Data");
Serial.println("Collecting Data");
static boolean newDataReady = 0;
const int serialPrintInterval = 0; //increase value to slow down serial print activity
// check for new data/start next conversion:
if (LoadCell.update()) newDataReady = true;
// get smoothed value from the dataset:
if (newDataReady) {
if (millis() > t + serialPrintInterval) {
float i = LoadCell.getData();
Serial.print("Output: ");
Serial.println(i);
newDataReady = 0;
t = millis();
}
}
delay(8000);
lcd.clear();
digitalWrite(LEDORANGE, LOW);
digitalWrite(10,LOW);
lcd.setCursor(0,0);
lcd.print("Complete");
Serial.println("Complete");
// receive command from serial terminal, send 't' to initiate tare operation:
if (Serial.available() > 0) {
char inByte = Serial.read();
if (inByte == 't') LoadCell.tareNoDelay();
}
// check if last tare operation is complete:
if (LoadCell.getTareStatus() == true) {
Serial.println("Tare complete");
}
}
}