// set pin numbers
const int HRbuttonPin = 32; // the number of the Heater Realy pushbutton pin
const int CRbuttonPin = 33; // the number of the Heater Realy pushbutton pin
const int HRledPin = 5; // the number of the LED pin
const int CRledPin = 16; // the number of the LED pin
// variable for storing the pushbutton status
int HRbuttonState = 0;
int CRbuttonState = 0;
int HRbuttonCycle=3; // the varible number times adjusted to make sure we don't over shoot target
int CRbuttonCycle=3; // the varible number times adjusted to make sure we don't over shoot target
//int initHRTempPulse = 3; // the initial number of times the switch should be pulsed to increase temp on induction plate
//int initCRTempPulse = 3; // the initial number of times the switch should be pulsed to decrease temp on induction plate
int zeroPulse = 1; // number of passes with relay on and zero pulses
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(HRbuttonPin, INPUT);
pinMode(CRbuttonPin, INPUT);
// initialize the LED pin as an output
pinMode(HRledPin, OUTPUT);
pinMode(CRledPin, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// read the state of the pushbutton value
HRbuttonState = digitalRead(HRbuttonPin);
CRbuttonState = digitalRead(CRbuttonPin);
// check if the pushbutton (relay) is pressed (energized).
// If it is, the buttonState is HIGH and the temperature of the wash needs to increase
// HRbuttonCycle = initHRTempPulse;
if (HRbuttonState == HIGH) {
Serial.println("Heater Relay Detected ON");
// turn LED on 5 times at 1 second intervals
for (int i = 0; i <= HRbuttonCycle; i++) {
digitalWrite(HRledPin, HIGH);
delay(1000);
digitalWrite(HRledPin, LOW);
delay(1000);
//Serial.println("initHRTempPulse = ");
//Serial.println(initHRTempPulse);
Serial.println("HRbuttonCycle = ");
Serial.println(HRbuttonCycle);
}
// delay 1 minute for cooling
// if it hasn't cooled enough (e.g. HR relay = high)
// we reduce the number of degrees (initTempPulse) we turn down the
// incudtion plate
Serial.println("WAIT BETWEEN CYCLES");
delay(30000); // delay for 30 seconds **** CHANGE FOR PROD ****
HRbuttonCycle = HRbuttonCycle - 1 ;
Serial.println("NEW value for HRbuttonCycle");
Serial.println(HRbuttonCycle);
// if we've gone through an entire temp gentle increase cycle of the induction plate
// then delay long time to let temperature catch up.
// Then cycle again wtih a smaller pulse start value
if (HRbuttonState == HIGH && HRbuttonCycle == 0) {
Serial.println("LONG wait between cycles");
delay(60000); // long delay to let temp catch up for induction plate temp change (1 minute) **** CHANGE FOR PROD *****
HRbuttonCycle = 2; // go through two more temp increase cycles
Serial.println("STARTING NEW SHORTER CYCLE");
Serial.println("HRbuttonCycle");
Serial.println(HRbuttonCycle);
}
}
if (CRbuttonState == HIGH) {
Serial.println("Heater Relay Detected ON");
// turn LED on 5 times at 1 second intervals
for (int i = 0; i <= CRbuttonCycle; i++) {
digitalWrite(CRledPin, HIGH);
delay(1000);
digitalWrite(CRledPin, LOW);
delay(1000);
//Serial.println("initCRTempPulse = ");
//Serial.println(initCRTempPulse);
Serial.println("CRbuttonCycle = ");
Serial.println(CRbuttonCycle);
}
// delay 1 minute for cooling
// if it hasn't cooled enough (e.g. CR relay = high)
// we reduce the number of degrees (initTempPulse) we turn down the
// incudtion plate
Serial.println("WAIT BETWEEN CYCLES");
delay(30000); // delay for 30 seconds **** CHANGE FOR PROD ****
CRbuttonCycle = CRbuttonCycle - 1 ;
Serial.println("NEW value for CRbuttonCycle");
Serial.println(CRbuttonCycle);
// if we've gone tCRough an entire temp gentle increase cycle of the induction plate
// then delay long time to let temperature catch up.
// Then cycle again wtih a smaller pulse start value
if (CRbuttonState == HIGH && CRbuttonCycle == 0) {
Serial.println("LONG wait between cycles");
delay(60000); // long delay to let temp catch up for induction plate temp change (1 minute) **** CHANGE FOR PROD *****
CRbuttonCycle = 2; // go tCRough two more temp increase cycles
Serial.println("STARTING NEW SHORTER CYCLE");
Serial.println("CRbuttonCycle");
Serial.println(CRbuttonCycle);
}
}
}