From d354be10778f41602654d93426631b651853cf59 Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Tue, 31 May 2022 13:53:19 +0200 Subject: [PATCH] relais added --- CMakeLists.txt | 2 +- gbmanager.cpp | 11 +++++++++++ relais.cpp | 23 +++++++++++++++++++++++ relais.h | 18 ++++++++++++++++++ 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 relais.cpp create mode 100644 relais.h diff --git a/CMakeLists.txt b/CMakeLists.txt index d67d624..c567f2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,7 @@ pico_sdk_init() # Add executable. Default name is the project name, version 0.1 -add_executable(gbmanager gbmanager.cpp lcd.cpp ds18b20.cpp) +add_executable(gbmanager gbmanager.cpp lcd.cpp ds18b20.cpp relais.cpp) pico_set_program_name(gbmanager "gbmanager") pico_set_program_version(gbmanager "0.1") diff --git a/gbmanager.cpp b/gbmanager.cpp index 56d99ca..8724de8 100644 --- a/gbmanager.cpp +++ b/gbmanager.cpp @@ -8,11 +8,15 @@ #include "config.h" #include "ds18b20.h" #include "lcd.h" +#include "relais.h" +// GPIOs used constexpr uint I2C_SDA_PIN = 26; constexpr uint I2C_SCL_PIN = 27; constexpr uint DS18B20_PIN = 28; +constexpr uint RELAIS_PIN = 18; +// Custom chars for the LCD constexpr char CUSTOM_CHAR_DEG = 0xDF; constexpr char CUSTOM_CHAR_AE = 0xE1; @@ -22,11 +26,16 @@ int main() { // Enable UART so we can print status output stdio_init_all(); + // Initialize the LCD auto myLCD = LCD(i2c1, I2C_SDA_PIN, I2C_SCL_PIN); myLCD.clear(); + // Initialize the temp sensor // DS18B20 ds = DS18B20(pio0, DS18B20_PIN); + // Initialize the relais + Relais relais(RELAIS_PIN); + float temp_act{0}; float temp_tgt{28.0}; float temp_diff{0.5}; @@ -56,6 +65,8 @@ int main() { } isHeating ? heatInfo = ">H<" : heatInfo = " "; + relais.activate(isHeating); + lcdText.str(""); lcdText.clear(); lcdText.precision(4); diff --git a/relais.cpp b/relais.cpp new file mode 100644 index 0000000..185868e --- /dev/null +++ b/relais.cpp @@ -0,0 +1,23 @@ +#include "relais.h" + +Relais::Relais(uint gpio) : gpio{gpio} { + gpio_set_dir(gpio, true); + gpio_init(gpio); + off(); +} + +void Relais::activate(bool active) { + if (active) { + gpio_pull_down(gpio); + } else { + gpio_pull_up(gpio); + } +} + +void Relais::on() { + activate(true); +} + +void Relais::off() { + activate(false); +} \ No newline at end of file diff --git a/relais.h b/relais.h new file mode 100644 index 0000000..f35fbee --- /dev/null +++ b/relais.h @@ -0,0 +1,18 @@ +#ifndef RELAIS_H +#define RELAIS_H + +#include "pico/stdlib.h" +#include "hardware/gpio.h" + +class Relais { + public: + Relais(uint gpio); + void activate(bool active); + void on(); + void off(); + + private: + uint gpio; +}; + +#endif \ No newline at end of file