43 lines
968 B
C++
43 lines
968 B
C++
#include "Valve.h"
|
|
#include "gpio_common.h"
|
|
|
|
#include <pico/stdlib.h>
|
|
|
|
|
|
int main() {
|
|
Valve cold_valve{10, 11, 12, 13};
|
|
Valve hot_valve{21, 20, 19, 18};
|
|
|
|
const int button_open = 14;
|
|
const int button_close = 15;
|
|
gpio_init_out(PICO_DEFAULT_LED_PIN);
|
|
gpio_init_input(button_open);
|
|
gpio_init_input(button_close);
|
|
|
|
const int tick_ms = 50;
|
|
while (true) {
|
|
if (gpio_get(button_open) == 0) {
|
|
cold_valve.open();
|
|
hot_valve.open();
|
|
}
|
|
if (gpio_get(button_close) == 0) {
|
|
cold_valve.close();
|
|
hot_valve.close();
|
|
}
|
|
sleep_ms(tick_ms);
|
|
const auto cst = cold_valve.process();
|
|
hot_valve.process();
|
|
switch (cst) {
|
|
case Valve::State::Opened:
|
|
case Valve::State::Closed: gpio_put(PICO_DEFAULT_LED_PIN, 1); break;
|
|
default: break;
|
|
}
|
|
if (cst == Valve::State::Opened || cst == Valve::State::Closed) {
|
|
gpio_put(PICO_DEFAULT_LED_PIN, 1);
|
|
} else {
|
|
gpio_put(PICO_DEFAULT_LED_PIN, 0);
|
|
}
|
|
}
|
|
return 0;
|
|
}
|