Moin, die variable " c" in der While- Schleife wird nicht aktualisiert. Ich kann leider den Fehler nicht finden. Kann mir evtl. jemand weiterhelfen?
Achso, ich bin Einsteiger und habe nicht soviel Erfahrung.
Danke.
/*
-------------------------------------------------------------------------------------
HX711_ADC
Arduino library for HX711 24-Bit Analog-to-Digital Converter for Weight Scales
Olav Kallhovd sept2017
-------------------------------------------------------------------------------------
*/
/*
Settling time (number of samples) and data filtering can be adjusted in the config.h file
For calibration and storing the calibration value in eeprom, see example file "Calibration.ino"
The update() function checks for new data and starts the next conversion. In order to acheive maximum effective
sample rate, update() should be called at least as often as the HX711 sample rate; >10Hz@10SPS, >80Hz@80SPS.
If you have other time consuming code running (i.e. a graphical LCD), consider calling update() from an interrupt routine,
see example file "Read_1x_load_cell_interrupt_driven.ino".
This is an example sketch on how to use this library
*/
#include <HX711_ADC.h>
#include <EEPROM.h>
#include <Wire.h>
#include <RTClib.h>
RTC_DS3231 rtc;
//pins:
const int HX711_dout = 4; //mcu > HX711 dout pin
const int HX711_sck = 5; //mcu > HX711 sck pin
const int Relais = 10;
const int Taster = 7;
int Buttonstate = 0;
//zeiten
//const int feedinginterval = 30 * 60 * 1000;
//HX711 constructor:
HX711_ADC LoadCell(HX711_dout, HX711_sck);
const int calVal_eepromAdress = 0;
unsigned long t = 0;
void setup() {
pinMode(Relais, OUTPUT);
pinMode(Taster, INPUT_PULLUP);
digitalWrite(Relais, HIGH);
Serial.begin(57600);
delay(10);
Serial.println();
Serial.println("Starting...");
Wire.begin();
if(!rtc.begin()) {
Serial.println("Kein RTC-Modul gefunden");
// wihle(1); // Stopt das Programm wenn kein RTC-Modul gefunden
}
// rtc.adjust(DateTime(2024,5,20,20,40,0));
//Serial.printIn(RTC-Modul Datum gesetzt);
LoadCell.begin();
//LoadCell.setReverseOutput(); //uncomment to turn a negative output value to positive
float calibrationValue; // calibration value (see example file "Calibration.ino")
calibrationValue = 1095.31; // 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);
// the following allows for getting a new load value
//LoadCell.tare();
//Serial.println("Place");
//delay(10000);
//LoadCell.refreshDataSet();
//float new_value = LoadCell.getNewCalibration(374);
//Serial.print("new loadv is: ");
//Serial.println(new_value);
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("Startup is complete");
}
}
void loop() {
digitalWrite(Relais, HIGH);
float c = LoadCell.getData();
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("Load_cell output val: ");
//Serial.println(i);
newDataReady = 0;
t = millis();
}
}
// char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
DateTime now = rtc.now();
//Serial.print(now.year(), DEC);
//Serial.print('/');
//Serial.print(now.month(), DEC);
// Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(" (");
//Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
// Serial.print(") ");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();
if ((now.second() == 5 || now.minute() == 0) && now.second() == 5) { //(millis() % 1000 == 0) {
// c = LoadCell.getData();
float f = (c - 50.0);
digitalWrite(Relais, LOW);
Serial.print("cl: ");
Serial.println(c);
//delay(1000);
Serial.print("fl: ");
Serial.println(c);
//delay(5000);
while (c >= f){
// c = LoadCell.getData();
digitalWrite(Relais, HIGH);
//delay(1000);
Serial.print("wl: ");
Serial.println(c);
}
}
Serial.print("c: ");
Serial.println(c);
// receive command from serial terminal, send 't' to initiate tare operation:
//if (Serial.available() > 0) {
//char inByte = Serial.read();
Buttonstate = digitalRead(Taster);
if (Buttonstate == LOW) {
LoadCell.tareNoDelay(); //inByte == 't'
}
// check if last tare operation is complete:
if (LoadCell.getTareStatus() == true) {
Serial.println("Tare complete");
}
}