I copied sketch from. Advanced PID project for BGA rework station[DIYBGA.COM] to work with OLED display 0.91inch 120x64 with I2C. i changed certain inputs points to adapt for Arduino nano (originally was written for Arduino Mega ) I checked each statement and adjusted accordingly for OLED. but for some reason its not working. I checked individual statement by putting in switch value. It showing the display and everything works for that case only. when Running for every case ..it doesn't show any display not even for setup menu.
I am new to Arduino . Please help.
Is this something related to EPROM size or command?
Or can someone modify it to just work with OLED.
/*DUAL LOOP PID CONTROLLER */
#include <EEPROM.h>
#include <Adafruit_MAX31855.h>
#include <PID_v1.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET 4
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
//ssr pins. Any variables ending in 1 have to do with top heater
//Any variables ending in 2 have to do with bottom heater
#define RelayPin1 3
#define RelayPin2 5
//current editing step pointer
int editStep = 0;
int buzzerPin = 2;
//declaring which pins buttons are connected to
int upSwitchPin = 14;
int downSwitchPin = 15;
int editSwitchPin = 16;
int cancelSwitchPin = 17;
int okSwitchPin = 11;
//declaring switch state
int upSwitchState = 0;
int downSwitchState = 0;
int leftSwitchState = 0;
int rightSwitchState = 0;
int editSwitchState = 0;
int cancelSwitchState = 0;
int okSwitchState = 0;
//profile stuff
byte currentProfile = 1;
int currentStep = 1;
byte profileSteps;
double rampRateStep[9];
int dwellTimerStep[9];
int kp1;
int ki1;
int kd1;
int kp2;
int ki2;
int kd2;
int setpointRamp;
int startTemp;
int temperatureStep[9];
int eepromAddress = 0;//starting eepromaddress
long previousMillis; //these are for counters
double counter;
//these are the different states of the sketch. We call different ones depending on conditions
// ***** TYPE DEFINITIONS *****
typedef enum REFLOW_STATE
{
REFLOW_STATE_IDLE,
REFLOW_STATE_MENU_STEPS,
REFLOW_STATE_MENU_BOTTOM_HEAT,
REFLOW_STATE_MENU_STEP_RAMP,
REFLOW_STATE_MENU_STEP_TARGET,
REFLOW_STATE_MENU_STEP_DWELL,
REFLOW_STATE_MENU_BOTTOM_P,
REFLOW_STATE_MENU_BOTTOM_I,
REFLOW_STATE_MENU_BOTTOM_D,
REFLOW_STATE_MENU_TOP_P,
REFLOW_STATE_MENU_TOP_I,
REFLOW_STATE_MENU_TOP_D,
REFLOW_STATE_STEP_RAMP,
REFLOW_STATE_STEP,
REFLOW_STATE_STEP_DWELL,
REFLOW_STATE_COMPLETE,
REFLOW_STATE_ERROR
}
refLOWState_t;
typedef enum REFLOW_STATUS //this is simply to check if refLOW should be running or not
{
REFLOW_STATUS_OFF,
REFLOW_STATUS_ON
}
refLOWStatus_t;
#define SENSOR_SAMPLING_TIME 1000 //read tc every second
refLOWStatus_t refLOWStatus;
// RefLOW oven controller state machine state variable
refLOWState_t refLOWState;
//TC read timer variables
unsigned long nextCheck1;
unsigned long nextRead1;
//PID stuff
double Setpoint1, Input1, Output1;
//Specify the links and initial tuning parameters
PID myPID1(&Input1, &Output1, &Setpoint1,kp1,ki1,kd1, DIRECT);
int WindowSize = 2000;
unsigned long windowStartTime;
//PID stuff
double Setpoint2, Input2, Output2;
//Specify the links and initial tuning parameters
PID myPID2(&Input2, &Output2, &Setpoint2,kp2,ki2,kd2,DIRECT);
//Alarm state boolean
boolean alarmOn=false;
//Update whole screen boolean
boolean updateScreen = true;
//31855 stuff - can be easily swapped for 6675
int thermoCLK = 13;
int thermoCS = 10;
int thermoDO = 12;
//31855 stuff - can be easily swapped for 6675
int thermoCLK2 = 7;
int thermoCS2 = 6;
int thermoDO2 = 4;
Adafruit_MAX31855 thermocouple1(thermoCLK, thermoCS, thermoDO);//top heater thermocouple
Adafruit_MAX31855 thermocouple2(thermoCLK2, thermoCS2, thermoDO2);//bottom heater thermocouple
void loadProfile()//this function loads whichever profile currentProfile variable is set to
{
profileSteps = EEPROM.read((currentProfile-1)*29);
Setpoint2 = EEPROM.read((currentProfile-1)*29 + 1);
for (int i=0; i<9; i+1) {
rampRateStep[i] = EEPROM.read((currentProfile-1)*29 + i + 2)/20;
i++;
}
for (int i=0; i<9; i+1) {
dwellTimerStep[i] = EEPROM.read((currentProfile-1)*29 + i + 11)*5;
i++;
}
for (int i=0; i<9; i+1) {
temperatureStep[i] = EEPROM.read((currentProfile-1)*29 + i + 20);
i++;
}
kp1 = EEPROM.read((currentProfile-1)*6 + 122);
ki1 = EEPROM.read((currentProfile-1)*6 + 123);
kd1 = EEPROM.read((currentProfile-1)*6 + 124);
kp2 = EEPROM.read((currentProfile-1)*6 + 125);
ki2 = EEPROM.read((currentProfile-1)*6 + 126);
kd2 = EEPROM.read((currentProfile-1)*6 + 127);
return;
}
void setup()
{
//setup pins as input for buttons
Serial.begin(9600);
pinMode (upSwitchPin, INPUT_PULLUP);
pinMode (downSwitchPin, INPUT_PULLUP);
pinMode (editSwitchPin, INPUT_PULLUP);
pinMode (cancelSwitchPin, INPUT_PULLUP);
pinMode (okSwitchPin, INPUT_PULLUP);
pinMode (buzzerPin, OUTPUT);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.setTextColor(WHITE);
display.clearDisplay();
display.setCursor(10, 0);
display.print("ARDUINO BGA REWORK ");
display.setCursor(50, 30);
display.print("V1.2");
display.display();
//Welcome melody
tone(buzzerPin, 523);
delay(200);
tone(buzzerPin, 659);
delay(200);
tone(buzzerPin, 784);
delay(200);
tone(buzzerPin, 1046);
delay(200);
noTone(buzzerPin);
// wait for MAX chips to stabilize and splash screen
delay(2000);
pinMode(RelayPin1, OUTPUT);//setup ssr pins as outputs
pinMode(RelayPin2, OUTPUT);
windowStartTime = millis();//Just total time sketch has been running
// Initialize time keeping variable for TC1
nextCheck1 = millis();
// Initialize top thermocouple reading variable
nextRead1 = millis();
//initialize soak timer variable
myPID1.SetOutputLimits(0, WindowSize);//myPID1 = top heater PID loop
myPID2.SetOutputLimits(0, WindowSize);
myPID1.SetMode(AUTOMATIC);
myPID2.SetMode(AUTOMATIC);
}
int i=0;
void loop()
{
upSwitchState = digitalRead(upSwitchPin);
downSwitchState = digitalRead(downSwitchPin);
editSwitchState = digitalRead(editSwitchPin);
cancelSwitchState = digitalRead(cancelSwitchPin);
okSwitchState = digitalRead(okSwitchPin);
unsigned long currentMillis = millis();
int sv1 = Setpoint1;
int sv2 = Setpoint2;
int tc1 = Input1;
int tc2 = Input2;
if (upSwitchState==LOW || downSwitchState==LOW || editSwitchState==LOW || cancelSwitchState==LOW || okSwitchState==LOW) {
tone(buzzerPin, 523);
delay(100);
noTone(buzzerPin);
}
if (refLOWState==REFLOW_STATE_COMPLETE || alarmOn){
if (i<15 && cancelSwitchState==HIGH) {
alarmOn=true;
tone(buzzerPin, 1046);
delay(100);
noTone(buzzerPin);
delay(100);
tone(buzzerPin, 1046);
delay(100);
noTone(buzzerPin);
delay(100);
tone(buzzerPin, 1046);
delay(100);
noTone(buzzerPin);
delay(100);
tone(buzzerPin, 1046);
delay(100);
noTone(buzzerPin);
delay(400);
i++;
}
else {
i=0;
alarmOn=false;
}
}
switch (refLOWState)
{
case REFLOW_STATE_IDLE:
if (millis() > nextRead1)
{
// Read thermocouples next sampling period
nextRead1 += SENSOR_SAMPLING_TIME;
display.setCursor(110, 27);
display.print(tc1);
display.setCursor(110, 37);
display.print(tc2);
display.display();
}
//Update whole screen only once
if (updateScreen) {
//setup idle screen
display.setCursor(0, 60);
display.print("IDLE");
display.setCursor(0, 17);
display.print("PTN:");
display.print(" STEP:1 ");
display.setCursor(0, 27);
display.print(" TH SV:");
display.setCursor(80, 27);
display.print("PV:");
display.setCursor(0, 37);
display.print(" BH SV:");
display.setCursor(80, 37);
display.print("PV:");
display.display();
updateScreen = false;
}
display.setCursor(10, 0);
display.print("CurrentProfile:");
display.print(currentProfile);
display.setCursor(0, 17);
display.print(temperatureStep[0]);
display.setCursor(0, 37);
display.print("SV 2:");
display.print(sv2);
display.display();
windowStartTime = millis();
if (upSwitchState == LOW)//if up switch is pressed go to next profile
{
currentProfile = currentProfile + 1;
delay(25);
if (currentProfile >= 5)//if currentProfile = 4 and up is pressed go back to profile 1
{
currentProfile = 1;
}
}
if (downSwitchState == LOW)//same as above just go down one profile
{
currentProfile = currentProfile - 1;
delay(25);
if (currentProfile <= 0)
{
currentProfile = 4;
}
}
loadProfile();
if (editSwitchState == LOW ) //if edit is pressed go to menu
{
delay(25);
refLOWState = REFLOW_STATE_MENU_STEPS;
//update next screen
updateScreen = true;
}
if (okSwitchState == LOW)
{
//update next screen
updateScreen = true;
refLOWStatus = REFLOW_STATUS_ON;
refLOWState = REFLOW_STATE_STEP_RAMP;
}
break;
case REFLOW_STATE_MENU_STEPS:
if (updateScreen) {
display.setCursor(20, 0);
display.print("Profile ");
display.print(currentProfile);
display.print(" Edit");
display.setCursor(0, 27);
display.print("Profile Steps:");
display.print(profileSteps);
display.display();
updateScreen = false;
}
display.setCursor(84, 27);
display.print(profileSteps);
display.display();
if (upSwitchState == LOW)
{
profileSteps = profileSteps + 1;
delay(25);
if (profileSteps >= 10) {
profileSteps = 1;
}
}
if (downSwitchState == LOW)
{
profileSteps = profileSteps - 1;
delay(25);
if (profileSteps <= 0) {
profileSteps = 9;
}
}
if (okSwitchState == LOW)
{
delay(25);
updateScreen = true;
refLOWState = REFLOW_STATE_MENU_BOTTOM_HEAT;
}
if (cancelSwitchState == LOW)
{
delay(25);
updateScreen = true;
refLOWState = REFLOW_STATE_IDLE;
}
break;
case REFLOW_STATE_MENU_BOTTOM_HEAT:
if (updateScreen) {
display.setCursor(0, 27);
display.print("Bottom Heat:");
updateScreen = false;
}
display.setCursor(84, 27);
display.print(sv2);
display.display();
if (upSwitchState == LOW)
{
Setpoint2 = Setpoint2 + 10;
delay(25);
if (Setpoint2 >= 350)
{
Setpoint2 = 350;
}
}
if (downSwitchState == LOW)
{
Setpoint2 = Setpoint2 - 10;
delay(25);
if (Setpoint2 <= 100)
{
Setpoint2 = 100;
}
}
if (okSwitchState == LOW)
{
delay(25);
updateScreen = true;
refLOWState = REFLOW_STATE_MENU_STEP_RAMP;
}
if (cancelSwitchState == LOW)
{
delay(25);
updateScreen = true;
refLOWState = REFLOW_STATE_IDLE;
}
break;
case REFLOW_STATE_MENU_STEP_RAMP:
if (updateScreen) {
display.setCursor(0, 27);
display.print("Step:");
display.print(editStep + 1);
display.setCursor(0, 37);
display.print("Ramp:");
updateScreen = false;
}
display.setCursor(50, 37);
display.print(rampRateStep[editStep]);
display.display();
if (upSwitchState == LOW)
{
rampRateStep[editStep] = rampRateStep[editStep] + .25;
delay(25);
if (rampRateStep[editStep] >= 9)
{
rampRateStep[editStep] = 9;
}
}
if (downSwitchState == LOW)
{
rampRateStep[editStep] = rampRateStep[editStep] - .25;
delay(25);
if (rampRateStep[editStep] <= .25)
{
rampRateStep[editStep] = .25;
}
}
if (okSwitchState == LOW)
{
delay(25);
updateScreen = true;
if (editStep + 1 == profileSteps){
editStep = 0;
refLOWState = REFLOW_STATE_MENU_STEP_TARGET;
}
else {
editStep++;
}
}
if (cancelSwitchState == LOW)
{
updateScreen = true;
editStep = 0;
delay(25);
refLOWState = REFLOW_STATE_IDLE;
}
break;
case REFLOW_STATE_MENU_STEP_TARGET:
if (updateScreen) {
display.setCursor(0, 27);
display.print("Step ");
display.print(editStep + 1);
display.setCursor(0, 37);
display.print("Target:");
display.print(temperatureStep[editStep]);
updateScreen = false;
display.display();
}
display.setCursor(42, 37);
display.print(temperatureStep[editStep]);
display.display();
if (upSwitchState == LOW)
{
temperatureStep[editStep] = temperatureStep[editStep] + 2;
delay(25);
if (temperatureStep[editStep] >= 250)
{
temperatureStep[editStep] = 250;
}
}
if (downSwitchState == LOW)
{
temperatureStep[editStep] = temperatureStep[editStep] - 2;
delay(25);
if (temperatureStep[editStep] <= 0)
{
temperatureStep[editStep] = 0;
}
if (temperatureStep[editStep] <= 99)
{
display.setCursor(18, 2);
display.print(" ");
display.display();
}
if (temperatureStep[editStep] <= 9)
{
display.setCursor(17, 2);
display.print(" ");
display.display();
}
}
if (okSwitchState == LOW)
{
delay(25);
updateScreen = true;
if (editStep + 1 == profileSteps){
editStep = 0;
refLOWState = REFLOW_STATE_MENU_STEP_DWELL;
}
else {
editStep++;
}
}
if (cancelSwitchState == LOW)
{
updateScreen = true;
delay(25);
editStep = 0;
refLOWState = REFLOW_STATE_IDLE;
}
break;
case REFLOW_STATE_MENU_STEP_DWELL:
if (updateScreen) {
display.setCursor(0, 27);
display.print("Step:");
display.print(editStep + 1);
display.setCursor(0, 37);
display.print("Dwell:");
display.print(dwellTimerStep[editStep]);
display.display();
}
display.setCursor(36, 37);
display.print(dwellTimerStep[editStep]);
display.display();
if (upSwitchState == LOW)
{
dwellTimerStep[editStep] = dwellTimerStep[editStep] + 5;
delay(25);
if (dwellTimerStep[editStep] >= 1000)
{
dwellTimerStep[editStep] = 1000;
}
}
if (downSwitchState == LOW)
{
dwellTimerStep[editStep] = dwellTimerStep[editStep] - 5;
delay(25);
if (dwellTimerStep[editStep] <= 0)
{
dwellTimerStep[editStep] = 0;
}
if (dwellTimerStep[editStep] <= 99) //????????????????????????????????????????????????????????????????????????
{
display.setCursor(18, 2);
display.display();
}
if (dwellTimerStep[editStep] <= 9)
{
display.setCursor(17, 2);
display.display();
}
}
if (okSwitchState == LOW)
{
delay(25);
updateScreen = true;
if (editStep + 1 == profileSteps){
editStep = 0;
refLOWState = REFLOW_STATE_MENU_BOTTOM_P;
}
else {
editStep++;
}
}
if (cancelSwitchState == LOW)
{
delay(25);
updateScreen = true;
editStep = 0;
refLOWState = REFLOW_STATE_IDLE;
}
break;
case REFLOW_STATE_MENU_BOTTOM_P:
if (updateScreen){
display.setCursor(20, 0);
display.print("Bottom Heater:");
display.setCursor(0, 27);
display.print("P=");
display.print(kp2);
updateScreen = false;
display.display();
}
display.setCursor(12, 27);
display.print(kp2);
display.display();
if (upSwitchState == LOW)
{
kp2 = kp2 + 1;
delay(25);
if (kp2 >= 500)
{
kp2 = 500;
}
}
if (downSwitchState == LOW)
{
kp2 = kp2 - 1;
delay(25);
if (kp2 <= 0)
{
kp2 = 0;
}
}
if (okSwitchState == LOW)
{
delay(25);
updateScreen = true;
refLOWState = REFLOW_STATE_MENU_BOTTOM_I;
}
if (cancelSwitchState == LOW)
{
delay(25);
updateScreen = true;
refLOWState = REFLOW_STATE_IDLE;
}
break;
case REFLOW_STATE_MENU_BOTTOM_I:
display.setCursor(0, 27);
display.print("I=");
display.print(ki2);
display.display();
if (upSwitchState == LOW)
{
ki2 = ki2 + 1;
delay(25);
if (ki2 >= 500)
{
ki2 = 500;
}
}
if (downSwitchState == LOW)
{
ki2 = ki2 - 1;
delay(25);
if (ki2 <= 0)
{
ki2 = 0;
}
}
if (okSwitchState == LOW)
{
delay(25);
refLOWState = REFLOW_STATE_MENU_BOTTOM_D;
}
if (cancelSwitchState == LOW)
{
delay(25);
refLOWState = REFLOW_STATE_IDLE;
}
break;
case REFLOW_STATE_MENU_BOTTOM_D:
display.setCursor(0, 27);
display.print("D=");
display.print(kd2);
display.display();
if (upSwitchState == LOW)
{
kd2 = kd2 + 1;
delay(25);
if (kd2 >= 500)
{
kd2 = 500;
}
}
if (downSwitchState == LOW)
{
kd2 = kd2 - 1;
delay(25);
if (kd2 <= 0)
{
kd2 = 0;
}
}
if (okSwitchState == LOW)
{
delay(25);
refLOWState = REFLOW_STATE_MENU_TOP_P;
}
if (cancelSwitchState == LOW)
{
delay(25);
refLOWState = REFLOW_STATE_IDLE;
}
break;
case REFLOW_STATE_MENU_TOP_P:
if (updateScreen){
display.setCursor(10, 0);
display.print("Top Heater:");
display.setCursor(0, 27);
display.print("P=");
display.print(kp1);
updateScreen = false;
display.display();
}
display.setCursor(12, 27);
display.print(kp1);
display.display();
if (upSwitchState == LOW)
{
kp1 = kp1 + 1;
delay(25);
if (kp1 >= 500)
{
kp1 = 500;
}
}
if (downSwitchState == LOW)
{
kp1 = kp1 - 1;
delay(25);
if (kp1 <= 0)
{
kp1 = 0;
}
}
if (okSwitchState == LOW)
{
delay(25);
updateScreen = true;
refLOWState = REFLOW_STATE_MENU_TOP_I;
}
if (cancelSwitchState == LOW)
{
delay(25);
updateScreen = true;
refLOWState = REFLOW_STATE_IDLE;
}
break;
case REFLOW_STATE_MENU_TOP_I:
display.setCursor(0, 27);
display.print("I=");
display.print(ki1);
display.display();
if (upSwitchState == LOW)
{
ki1 = ki1 + 1;
delay(25);
if (ki1 >= 500)
{
ki1 = 500;
}
}
if (downSwitchState == LOW)
{
ki1 = ki1 - 1;
delay(25);
if (ki1 <= 0)
{
ki1 = 0;
}
}
if (okSwitchState == LOW)
{
delay(25);
refLOWState = REFLOW_STATE_MENU_TOP_D;
}
if (cancelSwitchState == LOW)
{
delay(25);
refLOWState = REFLOW_STATE_IDLE;
}
break;
case REFLOW_STATE_MENU_TOP_D:
display.setCursor(0, 27);
display.print("D=");
display.print(kd1);
display.display();
if (upSwitchState == LOW)
{
kd1 = kd1 + 1;
delay(25);
if (kd1 >= 500)
{
kd1 = 500;
}
}
if (downSwitchState == LOW)
{
kd1 = kd1 - 1;
delay(25);
if (kd1 <= 0)
{
kd1 = 0;
}
}
if (okSwitchState == LOW)
{
//saving the current profile parameters
EEPROM.write((currentProfile-1)*29, profileSteps);
EEPROM.write((currentProfile-1)*29 + 1, Setpoint2);
for (int i=0; i<9; i+1) {
EEPROM.write(((currentProfile-1)*29 + i + 2), rampRateStep[i]*20);
i++;
}
for (int i=0; i<9; i+1) {
EEPROM.write(((currentProfile-1)*29 + i + 11), dwellTimerStep[i]/5);
i++;
}
for (int i=0; i<9; i+1) {
EEPROM.write(((currentProfile-1)*29 + i + 20), temperatureStep[i]);
i++;
}
EEPROM.write(((currentProfile-1)*6 + 122), kp1);
EEPROM.write(((currentProfile-1)*6 + 123), ki1);
EEPROM.write(((currentProfile-1)*6 + 124), kd1);
EEPROM.write(((currentProfile-1)*6 + 125), kp2);
EEPROM.write(((currentProfile-1)*6 + 126), ki2);
EEPROM.write(((currentProfile-1)*6 + 127), kd2);
delay(25);
display.clearDisplay();
refLOWState = REFLOW_STATE_IDLE;
}
if (cancelSwitchState == LOW)
{
delay(25);
display.clearDisplay();
refLOWState = REFLOW_STATE_IDLE;
}
break;
case REFLOW_STATE_STEP_RAMP:
//currentStep = 1;
if (updateScreen){
display.setCursor(50, 37);
display.print("RUN ");
updateScreen = false;
display.display();
}
startTemp = tc1;
display.setCursor(70, 37);
display.print(currentStep);
display.setCursor(80, 37);
display.print(sv2);
display.display();
//ramp rate counter
if(currentMillis - previousMillis > 1000 / rampRateStep[currentStep-1]) {//seconds counter
previousMillis = currentMillis;
counter = counter + 1;
setpointRamp = startTemp + counter;
display.setCursor(0, 27);
display.print(setpointRamp);
Setpoint1 = setpointRamp;
display.display();
}
if (setpointRamp >= temperatureStep[currentStep-1]) {
display.setCursor(0,47);
display.print(temperatureStep[currentStep-1]);
refLOWState = REFLOW_STATE_STEP;
display.display();
}
if (cancelSwitchState == LOW)
{
currentStep = 1;
counter = 0;
setpointRamp = 0;
refLOWStatus = REFLOW_STATUS_OFF;
refLOWState = REFLOW_STATE_IDLE;
updateScreen = true;
}
break;
case REFLOW_STATE_STEP:
Setpoint1 = temperatureStep[currentStep-1];
if (Input1 >= temperatureStep[currentStep-1])
{
counter = 0;
refLOWState = REFLOW_STATE_STEP_DWELL;
}
if (cancelSwitchState == LOW)
{
updateScreen = true;
currentStep = 1;
counter = 0;
setpointRamp = 0;
refLOWStatus = REFLOW_STATUS_OFF;
refLOWState = REFLOW_STATE_IDLE;
}
break;
case REFLOW_STATE_STEP_DWELL:
if(currentMillis - previousMillis > 1000) {
previousMillis = currentMillis;
counter = counter + 1;
}
if (counter == dwellTimerStep[currentStep-1]) {
counter = 0;
setpointRamp = 0;
if (profileSteps == 1) {
refLOWState = REFLOW_STATE_COMPLETE;
}
else {
currentStep++;
refLOWState = REFLOW_STATE_STEP_RAMP;
}
}
if (cancelSwitchState == LOW)
{
updateScreen = true;
currentStep = 1;
counter = 0;
setpointRamp = 0;
refLOWStatus = REFLOW_STATUS_OFF;
refLOWState = REFLOW_STATE_IDLE;
}
break;
case REFLOW_STATE_COMPLETE:
refLOWStatus = REFLOW_STATUS_OFF;
refLOWState = REFLOW_STATE_IDLE;
updateScreen = true;
break;
}
Input1 = thermocouple1.readCelsius();
Input2 = thermocouple2.readCelsius();
if (refLOWStatus == REFLOW_STATUS_ON)
{
if (millis() > nextRead1)
{
// Read thermocouples next sampling period
nextRead1 += SENSOR_SAMPLING_TIME;
display.setCursor(110, 27);
display.print(tc1);
display.setCursor(110, 37);
display.print(tc2);
display.display();
}
myPID1.SetTunings(kp1,ki1,kd1);
myPID2.SetTunings(kp2,ki2,kd2);
myPID1.Compute();
myPID2.Compute();
if(millis() - windowStartTime>WindowSize)
{ //time to shift the Relay Window
windowStartTime += WindowSize;
}
if(Output1 > millis() - windowStartTime) digitalWrite(RelayPin1,HIGH);
else digitalWrite(RelayPin1,LOW);
if(Output2 > millis() - windowStartTime) digitalWrite(RelayPin2,HIGH);
else digitalWrite(RelayPin2,LOW);
}
else
{
digitalWrite(RelayPin1, LOW);
digitalWrite(RelayPin2, LOW);
}
display.display();
}