Created
June 5, 2021 17:32
-
-
Save loginov-rocks/a6ee1173ae0b32c9ba575e358a4aa1e1 to your computer and use it in GitHub Desktop.
DIY Connected Espresso Machine: Boiler (Part 3) - main.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 "Relay.h" | |
#include "Boiler.h" | |
#define SERIAL_BAUDRATE 9600 | |
#define PUMP_RELAY_PIN 2 | |
#define BOILER_RELAY_PIN 3 | |
#define BOILER_IS_BOILING_PIN A0 | |
#define BOILER_IS_STEAM_PIN A1 | |
Relay pump(PUMP_RELAY_PIN); | |
Boiler boiler(BOILER_RELAY_PIN, BOILER_IS_BOILING_PIN, BOILER_IS_STEAM_PIN); | |
boolean isSwitchedToSteam = false; | |
boolean isSwitchedToCold = false; | |
void setup() { | |
Serial.begin(SERIAL_BAUDRATE); | |
Serial.print("Initial pump state: "); | |
Serial.println(pump.getState()); | |
Serial.print("Initial boiler state: "); | |
Serial.println(boiler.getState()); | |
// Switch pump on for 10 seconds to test wiring and catch up pressure in the boiler. | |
// Warning! Do not start to heat the empty boiler! | |
Serial.println("Test pump for 10 seconds..."); | |
pump.on(); | |
delay(10000); | |
pump.off(); | |
// Set target temp to Boiling and boiler will be switched on when first boiler.work() called. | |
Serial.println("Pump switched off, let's get some boiling water..."); | |
boiler.setTargetTemp(BoilerTemp::Boiling); | |
} | |
void loop() { | |
// Boiler heated up to Boiling temp, we can switch it to Steam and remember this to prevent repeating. | |
if (!isSwitchedToSteam && boiler.getTemp() == BoilerTemp::Boiling) { | |
Serial.println("Okey, we have boiling water, now we gonna raise the temperature up to steam..."); | |
boiler.setTargetTemp(BoilerTemp::Steam); | |
isSwitchedToSteam = true; | |
} | |
// Boiler heated up to Steam temp, so we can switch it off and remember this to prevent repeating. | |
if (!isSwitchedToCold && boiler.getTemp() == BoilerTemp::Steam) { | |
Serial.println("Wow, so hot! Cool down, lil' boila..."); | |
boiler.setTargetTemp(BoilerTemp::Cold); | |
isSwitchedToCold = true; | |
} | |
// Boiler cooled down, print a message, and set the flag to false to prevent repeating. | |
if (isSwitchedToCold && boiler.getTemp() == BoilerTemp::Cold) { | |
Serial.println("Boiler has cooled down, but be careful! It's temperature just below boiling."); | |
isSwitchedToCold = false; | |
} | |
boiler.work(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment