Fermenter display
This commit is contained in:
parent
c87c46ce9c
commit
c9a379eaae
@ -16,34 +16,50 @@ DS18B20 ds18b20("DS18B20", D4);
|
||||
|
||||
DS18B20Sensor input(ds18b20, 0, "");
|
||||
|
||||
PWMOutput heater(D2, "");
|
||||
PWMOutput heater(D2, "", 100);
|
||||
|
||||
PIDController pid("fermenter", input, heater, UNIT_TEMPERATURE_C, 500, 0.00000002, 0);
|
||||
|
||||
auto displayToggleInterval = 2000UL;
|
||||
|
||||
auto display = LedControl(13, 14, 15, 1);
|
||||
|
||||
void displayDecimal(int *digit, const double value) {
|
||||
const auto integer = static_cast<int>(value);
|
||||
const auto decimal = static_cast<int>((value - integer) * 10) % 10;
|
||||
display.setDigit(0, (*digit)++, decimal, false);
|
||||
display.setDigit(0, (*digit)++, integer % 10, true);
|
||||
display.setDigit(0, (*digit)++, integer / 10 % 10, false);
|
||||
void displayPrintf(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
char buffer[9];
|
||||
vsnprintf(buffer, sizeof buffer, format, args);
|
||||
int position = 0;
|
||||
for (char *b = buffer; *b != 0 && b < buffer + sizeof buffer; b++) {
|
||||
display.setChar(0, position++, *b, false);
|
||||
}
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void displayLoop() {
|
||||
static unsigned long lastDisplayInit = 0;
|
||||
if (lastDisplayInit == 0 || millis() - lastDisplayInit > 60 * 60 * 1000) {
|
||||
lastDisplayInit = millis();
|
||||
const auto now = millis();
|
||||
|
||||
static unsigned long lastInit = 0;
|
||||
if (lastInit == 0 || now - lastInit >= 60 * 60 * 1000) {
|
||||
lastInit = now;
|
||||
display.shutdown(0, true);
|
||||
display.shutdown(0, false);
|
||||
display.setIntensity(0, 4);
|
||||
display.clearDisplay(0);
|
||||
}
|
||||
auto digit = 0;
|
||||
displayDecimal(&digit, input.getValue());
|
||||
digit++;
|
||||
digit++;
|
||||
displayDecimal(&digit, pid.targetValue);
|
||||
|
||||
static auto mode = true;
|
||||
static auto lastMode = 0UL;
|
||||
if (lastMode == 0 || now - lastMode >= displayToggleInterval) {
|
||||
lastMode = now;
|
||||
mode = !mode;
|
||||
}
|
||||
|
||||
if (mode) {
|
||||
displayPrintf("%3.0f ", heater.getPercent());
|
||||
} else {
|
||||
displayPrintf("%-4.1f%4.1f", input.getValue(), pid.targetValue);
|
||||
}
|
||||
}
|
||||
|
||||
void httpStatus(AsyncWebServerRequest *request) {
|
||||
@ -111,6 +127,7 @@ void patrixLoop() {
|
||||
ds18b20.loop();
|
||||
input.loop();
|
||||
pid.loop();
|
||||
displayLoop();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Loading…
Reference in New Issue
Block a user