@Costas I assigned the setpoint as a double. However, it did not seem to work. When I press my physical button, the process should not advance immediately to userBtn();. However, that’s what it’s doing. It should wait for the temp to get above the setpoint (the value the slider is set to). It should stay in Function1 until that setpoint is reached.
On the topic of me using elapsedmillis.h - I wrote my code using this library and this is the way my delays are working in the functions. If at all possible, I’d rather not figure out how to use the SimpleTimer lib as my current method is working for delay purposes. BUT, if the elapsedmillis.h is what’s causing my problems, I’ll gladly ditch it and try to figure out the simple timer method. @Lichtsignaal
Here is my full code:
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(0, 1); // RX, TX
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleStream.h>
char auth[] = "AuthCode";
#include <elapsedMillis.h>
#include <LiquidCrystal.h>
#include <PID_v1.h>
#include <OneWire.h>
#include <DallasTemperature.h>
//PID setup
double Setpoint1, Input1, Output1;
PID myPID1(&Input1, &Output1, &Setpoint1, 200, 10, 15, DIRECT);
int WindowSize = 10000;
unsigned long windowStartTime;
//Sensors & components
const int v1 = 46;
const int v2 = 48;
const int v3 = 50;
const int v4 = 52;
const int p = 44;
const int h = 40;
const int a = 2;
const int sensor1 = 39;
const int sensor2 = 41;
const int Auto_btn = 22;
int A_btnState = 0; //
#define ONE_WIRE_BUS 51 //data wire is plugged into pin 2 on the Arduino
OneWire oneWire(ONE_WIRE_BUS); //setup a oneWire instance to communicate with any OneWire devices
//(not just Maxim/Dallas temperature ICs)
DallasTemperature sensors(&oneWire); //pass oneWire reference to Dallas Temperature.
elapsedMillis timeElapsed;
unsigned long previousMillis = 0;
unsigned long pDelay;
LiquidCrystal lcd(12, 11, 10, 9, 8, 7); //lcd pin declaration
byte customChar1[8] = {
0b11111,
0b11111,
0b11111,
0b11111,
0b11110,
0b11000,
0b10000,
0b11111
};
byte customChar2[8] = {
0b11111,
0b11110,
0b11100,
0b10000,
0b00000,
0b00000,
0b00000,
0b11111
};
byte customChar3[8] = {
0b11111,
0b01111,
0b00111,
0b00001,
0b00000,
0b00000,
0b00000,
0b11111
};
byte customChar4[8] = {
0b11111,
0b11111,
0b11111,
0b11111,
0b00111,
0b00011,
0b00001,
0b11111
};
byte customChar5[8] = {
0b11111,
0b00000,
0b01110,
0b01000,
0b01010,
0b01110,
0b00000,
0b11111
};
byte customChar6[8] = {
0b11111,
0b00000,
0b11011,
0b10101,
0b10101,
0b10001,
0b00000,
0b11111
};
byte customChar7[8] = {
0b11111,
0b00000,
0b01000,
0b01000,
0b01110,
0b01110,
0b00000,
0b11111
};
void setup() {
DebugSerial.begin(9600);
Serial.begin(9600);
Blynk.begin(auth, Serial);
lcd.begin(16, 2);
lcd.createChar(0, customChar1);
lcd.createChar(1, customChar2);
lcd.createChar(2, customChar3);
lcd.createChar(3, customChar4);
lcd.createChar(4, customChar5);
lcd.createChar(5, customChar6);
lcd.createChar(6, customChar7);
digitalWrite(v1, LOW);
digitalWrite(v2, LOW);
digitalWrite(v3, LOW);
digitalWrite(v4, LOW);
digitalWrite(p, LOW);
digitalWrite(h, LOW);
delay(150);
pinMode(v1, OUTPUT);
pinMode(v2, OUTPUT);
pinMode(v3, OUTPUT);
pinMode(v4, OUTPUT);
pinMode(p, OUTPUT);
pinMode(h, OUTPUT);
pinMode(a, OUTPUT);
pinMode(sensor1, INPUT_PULLUP); // HLT float switch set as input
pinMode(sensor2, INPUT_PULLUP); // BK float switch set as input
windowStartTime = millis();
myPID1.SetOutputLimits(0, WindowSize);
myPID1.SetMode(AUTOMATIC);
//begin reading sensors
sensors.begin();
delay(150);
}
BLYNK_WRITE(V10)
{
Setpoint1 = param.asDouble();
}
void loop() {
Blynk.run();
//sensors.requestTemperatures();
//float tempF_1 = sensors.getTempFByIndex(0);
//Blynk.virtualWrite(3, tempF_1);
A_btnState = digitalRead(Auto_btn);
if (A_btnState == LOW && digitalRead(sensor1) == HIGH) {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Auto Mode");
lcd.setCursor(0, 2);
lcd.print("Initializing...");
delay(3000);
Function1();
}
else {
lcd.setCursor(0, 0);
lcd.print("Abcd");
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.write(byte(0));
lcd.write(byte(1));
lcd.write(byte(2));
lcd.write(byte(3));
lcd.write(byte(4));
lcd.write(byte(5));
lcd.write(byte(6));
lcd.write(byte(0));
lcd.write(byte(1));
lcd.write(byte(2));
lcd.write(byte(3));
digitalWrite(v1, LOW);
digitalWrite(v2, LOW);
digitalWrite(v3, LOW);
digitalWrite(v4, LOW);
digitalWrite(p, LOW);
digitalWrite(h, LOW);
}
}
void Function1()
{
pDelay = millis() + 5000;
while (digitalRead(sensor1) == HIGH) {
Blynk.run();
sensors.requestTemperatures();
float tempF_1 = sensors.getTempFByIndex(0);
Blynk.virtualWrite(3, tempF_1);
unsigned long currentMillis = millis();
lcd.setCursor(0, 0);
lcd.print("Efgh");
lcd.setCursor(0, 2);
lcd.print("Temp: ");
lcd.print(tempF_1);
digitalWrite(v1, HIGH);
digitalWrite(v2, HIGH);
if (pDelay - millis() >= 5000) {
delay(100);
digitalWrite(p, HIGH);
}
else {
digitalWrite(p, LOW);
}
Input1 = tempF_1;
myPID1.Compute();
unsigned long now = millis();
if (now - windowStartTime > WindowSize) {
windowStartTime += WindowSize;
if (Output1 > now - windowStartTime) {
digitalWrite(h, HIGH);
}
else {
digitalWrite(h, LOW);
}
}
if (tempF_1 >= Setpoint1) {
lcd.clear();
UserBtn();
}
}
}
void UserBtn()
{
while (digitalRead(Auto_btn) == HIGH) {
Blynk.notify("Do something here!");
sensors.requestTemperatures();
float tempF_1 = sensors.getTempFByIndex(0);
//float tempF_2 = sensors.getTempFByIndex(1);
Blynk.virtualWrite(0, tempF_1);
lcd.setCursor(0, 0);
lcd.print("Something happened.");
lcd.setCursor(0, 2);
lcd.print("Press btn!");
tone(a, 2000);
delay(500);
noTone(a);
Input1 = tempF_1;
myPID1.Compute();
unsigned long now = millis();
if (now - windowStartTime > WindowSize) {
windowStartTime += WindowSize;
}
if (Output1 > now - windowStartTime) {
digitalWrite(h, HIGH);
}
else {
digitalWrite(h, LOW);
}
}
lcd.clear();
Step1();
}
void Step1()
{
while (digitalRead(sensor1) == HIGH) {
sensors.requestTemperatures();
float tempF_1 = sensors.getTempFByIndex(0);
//float tempF_2 = sensors.getTempFByIndex(1);
Blynk.virtualWrite(3, tempF_1);
lcd.setCursor(0, 0);
lcd.print("Ramping temp.");
lcd.setCursor(0, 2);
lcd.print("Temp: ");
lcd.print(tempF_1);
Input1 = tempF_1;
myPID1.Compute();
unsigned long now = millis();
if (now - windowStartTime > WindowSize) {
windowStartTime += WindowSize;
}
if (Output1 > now - windowStartTime) {
digitalWrite(h, HIGH);
}
else {
digitalWrite(h, LOW);
}
if (tempF_1 >= Setpoint1) {
lcd.clear();
Timer12();
}
}
}
void Timer12()
{
timeElapsed = 0;
while (timeElapsed < 10000) {
int mins = timeElapsed / 60000;
int sec = timeElapsed / 1000;
sensors.requestTemperatures();
float tempF_1 = sensors.getTempFByIndex(0);
//float tempF_2 = sensors.getTempFByIndex(1);
Blynk.virtualWrite(0, tempF_1);
lcd.setCursor(0, 0);
lcd.print("[Timer 1] T: ");
lcd.print(tempF_1);
lcd.print("F)");
lcd.setCursor(0, 2);
lcd.print("Elapsed t: ");
lcd.print(mins);
lcd.print(" min");
Input1 = tempF_1;
myPID1.Compute();
unsigned long now = millis();
if (now - windowStartTime > WindowSize) {
windowStartTime += WindowSize;
}
if (Output1 > now - windowStartTime) {
digitalWrite(h, HIGH);
}
else {
digitalWrite(h, LOW);
}
}
tone(a, 2000);
delay(1000);
noTone(a);
lcd.clear();
loop();
}