Part 1:
//Include the libraries
#include <LiquidCrystal.h>
#include <LiquidMenu.h>
#include "Button.h"
#include "DHT.h"
#include <RtcDS3231.h>
#include <SoftwareSerial.h>
#include <WiFiEsp.h>
#include <Wire.h>
// Pin mapping for the display
const byte LCD_RS = 22;
const byte LCD_E = 23;
const byte LCD_D4 = 24;
const byte LCD_D5 = 25;
const byte LCD_D6 = 26;
const byte LCD_D7 = 27;
//LCD R/W pin to ground
//10K potentiometer to VO
LiquidCrystal lcd(LCD_RS, LCD_E, LCD_D4, LCD_D5, LCD_D6, LCD_D7);
// Button objects instantiation
const bool pullup = true;
Button left(28, pullup);
Button right(29, pullup);
Button up(31, pullup);
Button down(30, pullup);
Button enter(32, pullup);
// Variables used for PWM and FAN control with callback functions.
const byte pwmPin = 8;
byte pwmLevel = 0;
const byte fan1pin = 2;
const byte fan2pin = 3;
//User input for fangroup 1 start/stopp setpoint ground value
int rfSetpoint1 = 55; //User input via the LCD
int tempSetpoint1 = 22; //User input via the LCD
//User input for fangroup 2 start/stopp setpoint ground value
int rfSetpoint2 = 55; //User input via the LCD, this is ground values
int tempSetpoint2 = 22; //User input via the LCD, this is ground values
//User input for humidity and temp-sensor 1 calibration
const int calibSetUpHum1 = -9;
const int calibSetUpTemp1 = 0;
//User input for humidity and temp-sensor 2 calibration
const int calibSetUpHum2 = 0;
const int calibSetUpTemp2 = 2;
// Variables for controlling a pin and displaying the state with text.
// char* is used for adding changing text to the LiquidLine object.
const byte ledPin = LED_BUILTIN;
bool ledState = LOW;
char* ledState_text;
char* Fan1State_text; //For putting the on/off text on the LCD-display
char* Fan2State_text; //For putting the on/off text on the LCD-display
const byte analogPin = A5; //Not used for now
unsigned short analogValue = 0; //Not used for now
LiquidLine welcome_line1(5, 0, "Mainpanel");
LiquidLine welcome_line2(3, 1, "HomeAutomation");
LiquidLine welcome_line3(0, 3, "(L)(R)(Dwn)(Up)(ENT)"); //[ L | R |Dwn|Up|ENT]
LiquidScreen welcome_screen(welcome_line1, welcome_line2, welcome_line3);
LiquidLine analog_line(0, 0, "Analog: ", analogValue); //Not used for now
LiquidLine ledState_line(0, 1, "LED is ", ledState_text);
LiquidScreen screen2(analog_line, ledState_line);
LiquidLine pwm_line(0, 0, "PWM level: ", pwmLevel);
LiquidScreen pwm_screen(pwm_line);
LiquidLine fan1_line1(0, 0, "ECO-VENT KAMIN"); //Menu for controlling Fan1 and changing its temp- humiditysetpoint.
LiquidLine fan1_line2(0, 1, "Fan 1 mode: ", Fan1State_text);
LiquidLine fan1_line3(0, 2, "Temp set : ", tempSetpoint1, " C");
LiquidLine fan1_line4(0, 3, "RF set : ", rfSetpoint1, " %");
LiquidScreen fan1_screen(fan1_line1, fan1_line2, fan1_line3, fan1_line4);
LiquidLine fan2_line1(0, 0, "ECO-VENT TORKRUM"); //Menu for controlling Fan2 and changing its temp- humiditysetpoint.
LiquidLine fan2_line2(0, 1, "Fan 2 mode: ", Fan2State_text);
LiquidLine fan2_line3(0, 2, "Temp set : ", tempSetpoint2, " C");
LiquidLine fan2_line4(0, 3, "RF set : ", rfSetpoint2, " %");
LiquidScreen fan2_screen(fan2_line1, fan2_line2, fan2_line3, fan2_line4);
LiquidLine pool_line(0, 0, "POOLSYSTEM 8X4"); //Menu for, in the future, controlling the poolstuff.
LiquidLine pool1_line(0, 1, "Circ pump mode : OFF");
LiquidLine pool2_line(0, 2, "Side lamp mode : OFF");
LiquidLine pool3_line(0, 3, "Front lamp mode: OFF");
LiquidScreen pool_screen(pool_line, pool1_line, pool2_line, pool3_line);
LiquidMenu menu(lcd);
//Function to be attached to the tempSetpoint1 (fan1) object.
void tempSetpoint1_up() { //Raises the tempsetpoint for Fan1 via the LCD-display.
if (tempSetpoint1 == 0) {
tempSetpoint1 ++;
} else {
tempSetpoint1 ++;
}
}
void tempSetpoint1_down() { //Lower the tempsetpoint for Fan1 via the LCD-display
if (tempSetpoint1 == 0) {
tempSetpoint1 --;
} else {
tempSetpoint1 --;
}
}
// Function to be attached to the rfSetpoint1 (fan1) object.
void rfSetpoint1_up() { //Raises the humiditysetpoint for Fan1 via the LCD-display
if (rfSetpoint1 == 0) {
rfSetpoint1 ++;
} else {
rfSetpoint1 ++;
}
}
void rfSetpoint1_down() { //Lower the humiditysetpoint for Fan1 via the LCD-display
if (rfSetpoint1 == 0) {
rfSetpoint1 --;
} else {
rfSetpoint1 --;
}
}
//Function to be attached to the tempSetpoint2 (fan2) object.
void tempSetpoint2_up() { //Raises the tempsetpoint for Fan2 via the LCD-display.
if (tempSetpoint2 == 0) {
tempSetpoint2 ++;
} else {
tempSetpoint2 ++;
}
}
void tempSetpoint2_down() { //Lower the tempsetpoint for Fan2 via the LCD-display.
if (tempSetpoint2 == 0) {
tempSetpoint2 --;
} else {
tempSetpoint2 --;
}
}
// Function to be attached to the rfSetpoint2 (fan2) object.
void rfSetpoint2_up() { //Raises the humiditysetpoint for Fan2 via the LCD-display
if (rfSetpoint2 == 0) {
rfSetpoint2 ++;
} else {
rfSetpoint2 ++;
}
}
void rfSetpoint2_down() { //Lower the humiditysetpoint for Fan2 via the LCD-display
if (rfSetpoint2 == 0) {
rfSetpoint2 --;
} else {
rfSetpoint2 --;
}
}
// Function to be attached to the pwm_line object.
void pwm_up() {
if (pwmLevel < 225) {
pwmLevel += 25;
} else {
pwmLevel = 250;
}
analogWrite(pwmPin, pwmLevel);
}
// Function to be attached to the pwm_line object.
void pwm_down() {
if (pwmLevel > 25) {
pwmLevel -= 25;
} else {
pwmLevel = 0;
}
analogWrite(pwmPin, pwmLevel);
}
// Function to be attached to the fan1_line2 object, starts and stops the Fan1 from the LCD-display.
void fan1_up() {
digitalWrite(fan1pin, HIGH);
}
void fan1_down() {
digitalWrite(fan1pin, LOW);
}
// Function to be attached to the fan2_line2 object, starts and stops the Fan2 from the LCD-display
void fan2_up() {
digitalWrite(fan2pin, HIGH);
}
void fan2_down() {
digitalWrite(fan2pin, LOW);
}
//Declare and initialise global arrays for WiFi settings
char ssid[] = "Telia-68651D";
char pass[] = "1DE0E3729E";
// Declare and initialise global variables/arrays for Thingspeak connection
const char server[] = "thingspeak.com";
const char thingspeakAPIKey[] = "ARFSZBIOMX8UA6AQ";
const int postingInterval = 60;
//Create new RTC module object
RtcDS3231 rtcModule;
//Create new DHT object
#define DHT1PIN 4 // Digital pin for Temp and Humidity-sensor 1
#define DHT2PIN 5 // Digital pin for Temp and Humidity-sensor 2
// Uncomment whatever type you're using!
#define DHT1TYPE DHT11 // DHT 11
#define DHT2TYPE DHT11 // DHT 11
//Initialise DHT-sensor
DHT dht1(DHT1PIN, DHT1TYPE);
DHT dht2(DHT2PIN, DHT2TYPE);
//Create new client object
WiFiEspClient client;
//Create WiFi module object on GPIO pin 10 (RX) and 11 (TX)
SoftwareSerial MySerial(10, 11);
//Declare and initialise variable for radio status
int status = WL_IDLE_STATUS;
//Declare global variables for time and temperature in RTC-module
int hours;
int minutes;
int seconds;
float temp;
//Declare global variables for humidity and temperature in DHT11-sensor
float t1;
float t2;
float h1;
float h2;
//Declare global variables/arrays for timing
int oldMinute; //This is for updating the time (minutes)
char lastSent[20]; //This is the last time Thingspeak has got its input