relais added

This commit is contained in:
Martin Brodbeck 2022-05-31 13:53:19 +02:00
parent 8b58b3a443
commit d354be1077
4 changed files with 53 additions and 1 deletions

View file

@ -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")

View file

@ -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);

23
relais.cpp Normal file
View file

@ -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);
}

18
relais.h Normal file
View file

@ -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