/*
-- Bread Prover --
This source code of graphical user interface
has been generated automatically by RemoteXY editor.
To compile this code using RemoteXY library 3.1.11 or later version
download by link http://remotexy.com/en/library/
To connect using RemoteXY mobile app by link http://remotexy.com/en/download/
- for ANDROID 4.11.4 or later version;
- for iOS 1.9.1 or later version;
This source code is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
*/
//////////////////////////////////////////////
// RemoteXY include library //
//////////////////////////////////////////////
// you can enable debug logging to Serial at 115200
//#define REMOTEXY__DEBUGLOG
// RemoteXY select connection mode and include library
#define REMOTEXY_MODE__ESP32CORE_BLE
#include <BLEDevice.h>
#include <RemoteXY.h>
#include "DHT.h"
#include <PIDController.h>
#include "TickTwo"
// RemoteXY connection settings
#define REMOTEXY_BLUETOOTH_NAME "RemoteXY"
// RemoteXY configurate
#pragma pack(push, 1)
uint8_t RemoteXY_CONF[] = // 27 bytes
{ 255,1,0,0,0,20,0,16,29,1,2,0,18,18,22,11,2,26,31,31,
79,78,0,79,70,70,0 };
// this structure defines all the variables and events of your control interface
struct {
// input variables
uint8_t Relay_1; // =1 if switch ON and =0 if OFF
// other variable
uint8_t connect_flag; // =1 if wire connected, else =0
} RemoteXY;
#pragma pack(pop)
/////////////////////////////////////////////
// END RemoteXY include //
/////////////////////////////////////////////
#define PIN_PWM_OUT 4
#define DHTPIN 27
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
DHT dht(DHTPIN, DHTTYPE);
double Setpoint = 25;
double t;
double output;
double Kp = 150;
double Ki = 1;
double Kd = 1;
double static_var = 20;
PIDController myPID;
void PrintTimerCallback(void);
TickTwo PrintTimer(PrintTimerCallback, 1000); //Print every second
void PrintTimerCallback(void){
Serial.print(t);
Serial.print(F(","));
Serial.print(output);
Serial.print(F(","));
Serial.println(static_var);
}
}
void setup()
{
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
Serial.println(F("END SETUP0"));
dht.begin();
Serial.println(F("END SETUP1"));
//RemoteXY_Init ();
pinMode (PIN_PWM_OUT, OUTPUT);
Serial.println(F("END SETUP2"));
myPID.begin();
myPID.setpoint(map(Setpoint,15,50,0,255));
myPID.tune(Kp, Ki, Kd); // Tune the PID, arguments: kP, kI, kD
myPID.limit(0, 255); // Limit the PID output between 0 and 255, this is important to get rid of integral windup!
PrintTimer.start();
}
void loop()
{
delay(50);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
t = dht.readTemperature();
output = myPID.compute(map(t,15,50,0,255));
//output = map(output,0,100,0,255);
/*
myPID.debug(&Serial, "myController", PRINT_INPUT | // Can include or comment out any of these terms to print
PRINT_OUTPUT | // in the Serial plotter
PRINT_SETPOINT |
PRINT_BIAS |
PRINT_P |
PRINT_I |
PRINT_D);
*/
// Compute heat index in Celsius (isFahreheit = false)
//float hic = dht.computeHeatIndex(t, h, false);
// Serial.print(F("Humidity: "));
// Serial.print(h);
/*
if (millis()%1000 == 0) {
//Serial.print(F(" Temperature: "));
Serial.print(t);
Serial.print(F(","));
Serial.print(output);
Serial.print(F(","));
Serial.println(static_var);
}
*/
analogWrite(PIN_PWM_OUT,output);
PrintTimer.update();
}