Hi there
I've made the code as shown. I display a preset temperature and a preset humidity. Those can be changed via 4 buttons +/- 0.1. This works and so does reading the current values. Everything's fine here.
Now I want to use a couple of relays to control a heater and a humidifier to adjust the invironment until the values meet the presets. This will not happen instantly and if I make the code wait for the right values (could be more than 10 minutes) the system will stall and leave me unable to e.g. adjust preset meanwhile.
My question:
How will I make the heating and humidifying processes run and still be able to adjust presets at the same time?
Kind regards,
Chris
#include <LCD5110_Basic.h>
#include <Button.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#define knap1 A1
#define knap2 A2
#define knap3 A3
#define knap4 A4
#define DHTPIN 3
int relae1 = 4;
int relae2 = 5;
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#define PULLUP true
#define INVERT true
#define DEBOUNCE_MS 20
LCD5110 myGLCD(8,9,10,11,12);
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];
extern uint8_t BigNumbers[];
float setTemp=37.0;
float setFugt=55.0;
Button KnapTempPlus(knap1, PULLUP, INVERT, DEBOUNCE_MS);
Button KnapTempMinus(knap2, PULLUP, INVERT, DEBOUNCE_MS);
Button KnapFugtPlus(knap3, PULLUP, INVERT, DEBOUNCE_MS);
Button KnapFugtMinus(knap4, PULLUP, INVERT, DEBOUNCE_MS);
void setup()
{
myGLCD.InitLCD();
dht.begin();
Serial.begin (9600);
pinMode(13, OUTPUT); // sluk onboard LED
digitalWrite(13,LOW); // sluk onboard LED
pinMode(relae1,OUTPUT);
pinMode(relae2,OUTPUT);
myGLCD.setFont(SmallFont);
myGLCD.print("Temp:", 0, 0);
myGLCD.print("~", 24, 12);
myGLCD.print("Fugt:", 0, 34);
myGLCD.print("%", 24, 42);
myGLCD.setFont(MediumNumbers);
myGLCD.print("-------", 0, 22);
}
void loop()
{
tjekKnapper();
float aktuelFugt = dht.readHumidity();
float t = dht.readTemperature(true);
float aktuelTemp = (float((((t - 32) * 5) / 9)));
myGLCD.setFont(SmallFont);
myGLCD.printNumF(float(setTemp), 1, 0, 8);
myGLCD.printNumF(float(setFugt), 1, 0, 42);
myGLCD.setFont(MediumNumbers);
myGLCD.printNumF(float(aktuelTemp), 1, 36, 0);
myGLCD.printNumF(float(aktuelFugt), 1, 36, 34);
}
void tjekKnapper()
{
tjekKnapTempPlus();
tjekKnapTempMinus();
tjekKnapFugtPlus();
tjekKnapFugtMinus();
}
void tjekKnapTempPlus()
{
KnapTempPlus.read();
if (KnapTempPlus.wasPressed()) {
setTemp +=0.1;
}
}
void tjekKnapTempMinus()
{
KnapTempMinus.read();
if (KnapTempMinus.wasPressed()) {
setTemp -=0.1;
}
}
void tjekKnapFugtPlus()
{
KnapFugtPlus.read();
if (KnapFugtPlus.wasPressed()) {
setFugt +=0.1;
}
}
void tjekKnapFugtMinus()
{
KnapFugtMinus.read();
if (KnapFugtMinus.wasPressed()) {
setFugt -=0.1;
}
}