Created
June 5, 2021 17:13
-
-
Save loginov-rocks/97928385cdc14b2b8685e260fd0301ec to your computer and use it in GitHub Desktop.
DIY Connected Espresso Machine: Boiler (Part 3) - Boiler.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "Boiler.h" | |
Boiler::Boiler(int relayPin, int _isBoilingPin, int _isSteamPin) : Relay(relayPin) | |
{ | |
// Configure pins. | |
isBoilingPin = _isBoilingPin; | |
isSteamPin = _isSteamPin; | |
pinMode(isBoilingPin, INPUT_PULLUP); | |
pinMode(isSteamPin, INPUT_PULLUP); | |
} | |
boolean Boiler::getState() | |
{ | |
return Relay::getState(); | |
} | |
BoilerTemp Boiler::getTemp() | |
{ | |
// The steam check goes first because the temp is hotter than when boiling. | |
if (digitalRead(isSteamPin)) | |
{ | |
return BoilerTemp::Steam; | |
} | |
if (digitalRead(isBoilingPin)) | |
{ | |
return BoilerTemp::Boiling; | |
} | |
return BoilerTemp::Cold; | |
} | |
BoilerTemp Boiler::getTargetTemp() | |
{ | |
return targetTemp; | |
} | |
void Boiler::setTargetTemp(BoilerTemp _targetTemp) | |
{ | |
targetTemp = _targetTemp; | |
} | |
void Boiler::work() | |
{ | |
BoilerTemp temp = getTemp(), | |
targetTemp = getTargetTemp(); | |
// Switch relay off if the target temp is achieved. | |
if (targetTemp == BoilerTemp::Cold || temp == targetTemp || (temp == BoilerTemp::Steam && targetTemp == BoilerTemp::Boiling)) | |
{ | |
off(); | |
} | |
else | |
{ | |
on(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment