Last active
November 20, 2021 15:51
-
-
Save loginov-rocks/ca233d7fce4953092067197c9220e12b to your computer and use it in GitHub Desktop.
DIY Connected Espresso Machine: Toggle (Part 4) - 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" | |
#include "Toggle.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 | |
#define TOGGLE_PIN A2 | |
Relay pump(PUMP_RELAY_PIN); | |
Boiler boiler(BOILER_RELAY_PIN, BOILER_IS_BOILING_PIN, BOILER_IS_STEAM_PIN); | |
Toggle toggle(TOGGLE_PIN); | |
void printlnToggleState(ToggleState toggleState) | |
{ | |
switch (toggleState) | |
{ | |
case ToggleState::Boil: | |
Serial.println("BOIL"); | |
break; | |
case ToggleState::MakeSteam: | |
Serial.println("MAKE_STEAM"); | |
break; | |
case ToggleState::PourWater: | |
Serial.println("POUR_WATER"); | |
break; | |
default: | |
Serial.println("OFF"); | |
break; | |
} | |
} | |
void setup() | |
{ | |
Serial.begin(SERIAL_BAUDRATE); | |
Serial.print("Initial pump state: "); | |
Serial.println(pump.getState()); | |
Serial.print("Initial boiler state: "); | |
Serial.println(boiler.getState()); | |
Serial.print("Initial toggle state: "); | |
printlnToggleState(toggle.getState()); | |
} | |
void loop() | |
{ | |
// Get toggle state before checking whether it was toggled to have the flag up to date. | |
ToggleState toggleState = toggle.getState(); | |
if (toggle.getIsToggled()) | |
{ | |
Serial.print("Toggle switched to state: "); | |
printlnToggleState(toggleState); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment