Code Not working for OLED with arduino Nano

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();
}

Please follow the advice given in the link below when posting code. Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

1 Like

If you put all of your pin naming in one place you will see that OLED_RESET and thermoDO2 both use Pin 4. Move one to Pin 8 or Pin 9 which are not currently used.

const byte buzzerPin = 2;
const byte RelayPin1 = 3;
const byte OLED_RESET = 4;
const byte thermoDO2 = 4;
const byte RelayPin2 = 5;
const byte thermoCS2 = 6;
const byte thermoCLK2 = 7;
// 8
// 9
const byte thermoCS = 10;
const byte okSwitchPin = 11;
const byte thermoDO = 12;
const byte thermoCLK = 13;
const byte upSwitchPin = A0;
const byte downSwitchPin = A1;
const byte editSwitchPin = A2;
const byte cancelSwitchPin = A3;

There were a number of semantic problems in the code. Here is a version that compiles without warnings:

/*DUAL LOOP PID CONTROLLER */

#include <EEPROM.h>
#include <Adafruit_MAX31855.h>
#include <PID_v1.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>

//ssr pins. Any variables ending in 1 have to do with top heater
//Any variables ending in 2 have to do with bottom heater
const byte buzzerPin = 2;
const byte RelayPin1 = 3;
const byte OLED_RESET = 4;  // CONFLICT
const byte thermoDO2 = 4;   // CONFLICT
const byte RelayPin2 = 5;
const byte thermoCS2 = 6;
const byte thermoCLK2 = 7;
// 8
// 9
const byte thermoCS = 10;
const byte okSwitchPin = 11;
const byte thermoDO = 12;
const byte thermoCLK = 13;
const byte upSwitchPin = A0;
const byte downSwitchPin = A1;
const byte editSwitchPin = A2;
const byte cancelSwitchPin = A3;


//current editing step pointer
int editStep = 0;

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


//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

unsigned 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;

enum refLOWStatus_t //this is simply to check if refLOW should be running or not
{
  REFLOW_STATUS_OFF,
  REFLOW_STATUS_ON
};

#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);
unsigned 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;

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++)
  {
    rampRateStep[i]    = EEPROM.read((currentProfile - 1) * 29 + i + 2) / 20;
    dwellTimerStep[i]  = EEPROM.read((currentProfile - 1) * 29 + i + 11) * 5;
    temperatureStep[i] = EEPROM.read((currentProfile - 1) * 29 + i + 20);
  }

  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);
}

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);
}

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)
  {
    static int alarmCount = 0;
    if (alarmCount < 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);
      alarmCount++;
    }
    else
    {
      alarmCount = 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++)
        {
          EEPROM.write(((currentProfile - 1) * 29 + i + 2), rampRateStep[i] * 20);
          EEPROM.write(((currentProfile - 1) * 29 + i + 11), dwellTimerStep[i] / 5);
          EEPROM.write(((currentProfile - 1) * 29 + i + 20), temperatureStep[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;

    case REFLOW_STATE_ERROR:
      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();
}

i thought OLED uses PIN 4 of analog. i Changed the thermoDO2 to 8 still no light in oled display. As i currently dont have the sensor and the amplifier ..i am currently not using the sensor input/output i.e
thermoDO2 = 8;
thermoCS2 = 6;
thermoCLK2 = 7;

thermoCS = 10;
thermoDO = 12;
thermoCLK=13;

are kept open. Still it should display something.

when i mask (/* ....*/) form switch (refLOWState) statement i get a display. also i when manually put refLOWState=REFLOW_STATE_IDLE or REFLOW_STATE_MENU_STEPS or any other cases just before the switch statement..its shows display for that case. but runing as whole there is no display... not even the display command which is used in setup section.

Even with conflicting pins there were no compilation error.
Also there is no compilation error when changed the PIn as suggested.

Well its when tested with 16x2 lcd display with I2C communication with original code that was written for 16x4 display without I2C ...works and shows display ..not completely but half ( due to 16x2 display).But point is the code runs ..but not with oled !!!:thinking:

Maybe it’s a memory issue and the display doesn’t actually “ start “.
Remove a chunk of code and see if the display starts to work .
I seem to recall some oled examples have a print statement if memory is too low for the display ( even tho it may compile ok and not show low memory at that stage).
It might be the reason a Mega was used .

Almost certainly lack of memory for the display buffer, you might want to look at the U8g2 library using the page buffer, that greatly reduces the amount of ram needed.

Also look at the F() macro for the print statements with text literals, that will free up some ram but not enough to get the code working.

The code has a lot of problems - hard to believe it ran properly when there were several instances of the following:

  for (int i = 0; i < 9; i + 1) {

Only because each of those misbegotten loops ended with the line "i++;".

I noticed that, but very sloppy programming in my opinion, since the i + 1 serves no function.

i changed the library to u8x8, corrected many steps by best of my knowledge and masked the EEPROM line,..it works but the concern is that as there is no refresh option in u8x8 lib ... the variable value leaves the as it is where the digit do not change ....

like if variable x gets increment of one, its prints/displays good i.e., 1 ,2,3,4,5,6,7,8,9,10 but when it reduces it shows 10,90, 80,70,60,50,40,30,20,10,00 i.e. second digit doesn't gets off and if again increment is made its prints 10,20,30,40.....

for temporary I used float or double syntax so i could read the value before decimals ...

/*DUAL LOOP PID CONTROLLER */

#include <Arduino.h>
#include <EEPROM.h>
#include <Adafruit_MAX31855.h>
#include <Wire.h>
#include <PID_v1.h>
#include <U8x8lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); 
//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=1;

double rampRateStep[9];

double dwellTimerStep[9];

float kp1;
float ki1;
float kd1;
float kp2;
float ki2;
float 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 = 8;  
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;
  }
  for (int i=0; i<9; i+1) {
    dwellTimerStep[i] = EEPROM.read((currentProfile-1)*29 + i + 11)*5;
  }
  for (int i=0; i<9; i+1) {
    temperatureStep[i] = EEPROM.read((currentProfile-1)*29 + i + 20);
  }
  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);
  u8x8.begin();
  u8x8.setPowerSave(0);
  u8x8.setFont(u8x8_font_5x7_r);
  u8x8.drawString(3,0,"BGA REWORK ");
  u8x8.drawString(6,3,"V1.2");   
  delay(1000);
  u8x8.clear();
  //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(1000);
  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);
//intilization of front menu
  refLOWState=REFLOW_STATE_IDLE;
}
int i=0;
void loop()
{
  upSwitchState =     digitalRead(upSwitchPin);
  downSwitchState =   digitalRead(downSwitchPin);
  editSwitchState =   digitalRead(editSwitchPin);
  cancelSwitchState = digitalRead(cancelSwitchPin);
  okSwitchState =     digitalRead(okSwitchPin);

  unsigned long currentMillis = millis();

  double sv1 = Setpoint1;
  double sv2 = Setpoint2;

  double tc1 = Input1;
  double 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;
      u8x8.setCursor(6, 2);
      u8x8.print(sv1);
      u8x8.setCursor(6, 3);
      u8x8.print(tc1);
      u8x8.setCursor(6, 5);
      u8x8.print(sv2);
      u8x8.setCursor(6, 6);
      u8x8.print(tc2);  
    }

    //Update whole screen only once
    if (updateScreen) {
      u8x8.clear();
      u8x8.drawString(5,0,"IDLE");
      u8x8.drawString(0, 1,"PTN:    STEP:");
      u8x8.drawString(0, 2,"TH SV:");
      u8x8.drawString(0, 3,"TH PV:");
      u8x8.drawString(0, 5,"BH SV:");
      u8x8.drawString(0, 6,"BH PV:");
      u8x8.drawString(0, 7,"TARGET TEMP:");
      updateScreen = false;
    }
      u8x8.setCursor(4, 1);
      u8x8.print(currentProfile);
      u8x8.setCursor(13, 1);
      u8x8.print(currentStep);

      u8x8.setCursor(13, 7);
      u8x8.print(temperatureStep[0]);

      windowStartTime = millis();
    if (upSwitchState == LOW)//if up switch is pressed go to next profile
    {
      currentProfile++;
      delay(100);
      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--;
      delay(100);
      if (currentProfile <= 0)
      {
        currentProfile = 4;
      }
    }
 loadProfile();
    if (editSwitchState == LOW ) //if edit is pressed go to menu
    {
      delay(100);
      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) {
      u8x8.clear();
      u8x8.drawString(0, 0,"PROFILE");
      u8x8.setCursor(8, 0);
      u8x8.print(currentProfile);
      u8x8.drawString(10,0,"EDIT");
      u8x8.drawString(0, 3,"PROFILE STEP:");
      updateScreen = false;
      
      
    }
      u8x8.setCursor(13, 3);
      u8x8.print(profileSteps);
    if (upSwitchState == LOW)
    {
      profileSteps++;
      delay(100);
      if (profileSteps >= 10) {
        profileSteps = 1;
      }
    }
    if (downSwitchState == LOW)
    {
      profileSteps--;
      delay(100);
      if (profileSteps <= 0) {
        profileSteps = 9;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_BOTTOM_HEAT;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_IDLE;
    }

    break;



    
  case REFLOW_STATE_MENU_BOTTOM_HEAT:

   if (updateScreen) {
    u8x8.clear();
    u8x8.drawString(0,0,"BOTTOM HEATER");
    u8x8.drawString(0,3,"TEMP:");
    updateScreen = false;
     
    }
   u8x8.setCursor(10, 3);
   u8x8.print(sv2);
    
    if (upSwitchState == LOW)
    {
      Setpoint2 = Setpoint2 + 10;
      delay(100);
      if (Setpoint2 >= 350)
      {
        Setpoint2 = 350;
      }
    }
    if (downSwitchState == LOW)
    {
      Setpoint2 = Setpoint2 - 10;
      delay(100);
      if (Setpoint2 <= 0)
      {
        Setpoint2 = 0;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_STEP_RAMP;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;


    
    
  case REFLOW_STATE_MENU_STEP_RAMP:

    if (updateScreen) {
        u8x8.clear();
        u8x8.drawString(0, 3,"STEP:");
        u8x8.setCursor(6,3);
        u8x8.print(editStep + 1);
        u8x8.drawString(0, 6,"RAMP:");
        updateScreen = false;
      
    }
    u8x8.setCursor(6, 6);
    u8x8.print(rampRateStep[editStep]);
    if (upSwitchState == LOW)
    {
      rampRateStep[editStep] = rampRateStep[editStep] + .25;
      delay(100);
      if (rampRateStep[editStep] >= 9)
      {
        rampRateStep[editStep] = 9;
      }
    }
    if (downSwitchState == LOW)
    {
      rampRateStep[editStep] = rampRateStep[editStep] - .25;
      delay(100);
      if (rampRateStep[editStep] <= .25)
      {
        rampRateStep[editStep] = .00;
      }
    }
    if (okSwitchState == LOW)
    {
      updateScreen = true;
      delay(100);
      if (editStep + 1 == profileSteps){
        editStep = 0;
        refLOWState = REFLOW_STATE_MENU_STEP_TARGET;
      } 
      else {
        editStep++;
      }
    }
    if (cancelSwitchState == LOW)
    {
      updateScreen = true;
      editStep = 0; 
      delay(100);
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;


    
 
   case REFLOW_STATE_MENU_STEP_TARGET:
    if (updateScreen) {
      u8x8.clear();
      u8x8.drawString(0, 3,"STEP:");
      u8x8.setCursor(6,3);
      u8x8.print(editStep + 1);
      u8x8.drawString(0,6,"TARGET:");
      updateScreen = false;
    }
      u8x8.setCursor(8,6);
      u8x8.print(temperatureStep[editStep]);
      
    if (upSwitchState == LOW)
    {
      temperatureStep[editStep] = temperatureStep[editStep] + 2;
      delay(100);
      if (temperatureStep[editStep] >= 250)
      {
        temperatureStep[editStep] = 250;
      }
    }
    if (downSwitchState == LOW)
    {
      temperatureStep[editStep] = temperatureStep[editStep] - 2;
      delay(100);
      if (temperatureStep[editStep] <= 0)
      {
        temperatureStep[editStep] = 0;
      }   
     
    }

    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      if (editStep + 1 == profileSteps){
        editStep = 0;
        refLOWState = REFLOW_STATE_MENU_STEP_DWELL;
      } 
      else {
        editStep++;
      }
    }  
    if (cancelSwitchState == LOW)
    {
      updateScreen = true;
      delay(100);
      editStep = 0;
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;


    

  case REFLOW_STATE_MENU_STEP_DWELL:

    if (updateScreen) {
      u8x8.clear();
      u8x8.drawString(0, 3,"STEP:");
      u8x8.setCursor(6,3);
      u8x8.print(editStep + 1);
      u8x8.drawString(0, 5,"DWELL:");
       updateScreen = false;

    }

      u8x8.setCursor(8,5);
      u8x8.print(dwellTimerStep[editStep]);

    if (upSwitchState == LOW)
    {
      dwellTimerStep[editStep] = dwellTimerStep[editStep] + 5;
      delay(100);
      if (dwellTimerStep[editStep] >= 1000)
      {
        dwellTimerStep[editStep] = 1000;
      }
    }
    if (downSwitchState == LOW)
    {

      dwellTimerStep[editStep] = dwellTimerStep[editStep] - 5;
      delay(100);
      if (dwellTimerStep[editStep] <= 0)
      {
        dwellTimerStep[editStep] = 0;
      }

    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      if (editStep + 1 == profileSteps){

        editStep = 0;
        refLOWState = REFLOW_STATE_MENU_BOTTOM_P;
      } 
      else {
        editStep++;
      }
    }   
    if (cancelSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      editStep = 0;
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;



    

  case REFLOW_STATE_MENU_BOTTOM_P:
    if (updateScreen){
   u8x8.clear();
      u8x8.drawString(0, 0,"BOTTOM HEATER:");
      u8x8.drawString(0, 3,"P=");
      updateScreen = false;
    }
  
      u8x8.setCursor(3,3);
      u8x8.print(kp2);
  
    if (upSwitchState == LOW)
    {
      kp2++;
      delay(100);
      if (kp2 >= 500)
      {
        kp2 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      kp2--;
      delay(100);
      if (kp2 <= 0)
      {
        kp2 = 0;
      }

    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_BOTTOM_I;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;


    
  case REFLOW_STATE_MENU_BOTTOM_I:
     if (updateScreen){
      u8x8.clear();
      u8x8.drawString(0, 0,"BOTTOM HEATER:");
      u8x8.drawString(0, 3,"I=");
      updateScreen = false;
     }
    u8x8.setCursor(3,3);
    u8x8.print(ki2);
    if (upSwitchState == LOW)
    {
      ki2++;
      delay(100);
      if (ki2 >= 500)
      {
        ki2 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      ki2--;
      delay(100);
      if (ki2 <= 0)
      {
        ki2 = 0;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_BOTTOM_D;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      refLOWState = REFLOW_STATE_IDLE;
    }  
    break;


    

  case REFLOW_STATE_MENU_BOTTOM_D:
     if (updateScreen){
      u8x8.clear();
      u8x8.drawString(0, 0,"BOTTOM HEATER:");
     u8x8.drawString(0, 3,"D=");
      updateScreen = false;
     }    
    u8x8.setCursor(3,3);
    u8x8.print(kd2);
    if (upSwitchState == LOW)
    {
      kd2++;
      delay(100);
      if (kd2 >= 500)
      {
        kd2 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      kd2--;
      delay(100);
      if (kd2 <= 0)
      {
        kd2 = 0;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_TOP_P;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      refLOWState = REFLOW_STATE_IDLE;
    }  
    break;


    

  case REFLOW_STATE_MENU_TOP_P:
    if (updateScreen){
      u8x8.clear();
      u8x8.drawString(0, 0,"TOP HEATER:");
      u8x8.drawString(0, 3,"P=");
      u8x8.setCursor(3,3);
      u8x8.print(kp1);
      updateScreen = false;
    }
      u8x8.setCursor(3,3);
      u8x8.print(kp1);
    if (upSwitchState == LOW)
    {
      kp1++;
      delay(100);
      if (kp1 >= 500)
      {
        kp1 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      kp1--;
      delay(100);
      if (kp1 <= 0)
      {
        kp1 = 0;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_TOP_I;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;
  case REFLOW_STATE_MENU_TOP_I:
      if (updateScreen){
      u8x8.clear();
      u8x8.drawString(0, 0,"TOP HEATER:");
      u8x8.drawString(0, 3,"I=");
      updateScreen = false;
     }
    u8x8.setCursor(3,3);
    u8x8.print(ki1);
    if (upSwitchState == LOW)
    {
      ki1++;
      delay(100);
      if (ki1 >= 500)
      {
        ki1 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      ki1--;
      delay(100);
      if (ki1 <= 0)
      {
        ki1 = 0;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_TOP_D;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      refLOWState = REFLOW_STATE_IDLE;
    }  
    break;

  case REFLOW_STATE_MENU_TOP_D:
     if (updateScreen){
      u8x8.clear();
      u8x8.drawString(0, 0,"TOP HEATER:");
      u8x8.drawString(0, 3,"D=");
      updateScreen = false;
     }
    u8x8.setCursor(3,3);
    u8x8.print(kd1);
    if (upSwitchState == LOW)
    {
      kd1++;
      delay(100);
      if (kd1 >= 500)
      {
        kd1 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      kd1--;
      delay(100);
      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++) {
        EEPROM.write(((currentProfile-1)*29 + i + 2), rampRateStep[i]*20);

      }
      for (int i=0; i<9; i++) {
        EEPROM.write(((currentProfile-1)*29 + i + 11), dwellTimerStep[i]/5);
   
      }
      for (int i=0; i<9; i++) {
        EEPROM.write(((currentProfile-1)*29 + i + 20), temperatureStep[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);
      */
      u8x8.clear();
     delay(100);
     u8x8.setCursor(0,4);
     u8x8.print("SETTING SAVED");
     delay (2000);
     updateScreen = true;
     refLOWState = REFLOW_STATE_IDLE;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      refLOWState = REFLOW_STATE_IDLE;
    }  
    break;

  case REFLOW_STATE_STEP_RAMP:
    //currentStep = 1;
    if (updateScreen){
      u8x8.clear();
      u8x8.drawString(7, 0,"RUN ");
      u8x8.drawString(0,1, "CURRENT STEP:");
      u8x8.drawString(0, 2,"TH SV:");
      u8x8.drawString(0, 3,"TH PV:");
      u8x8.drawString(0, 5,"BH SV:");
      u8x8.drawString(0, 6,"BH PV:");
      u8x8.drawString(0, 7,"TARGET COMP:");
      updateScreen = false;
      delay(100);
    }
    startTemp = tc1;
    u8x8.setCursor(13,1);
    u8x8.print(currentStep);
    u8x8.setCursor(6, 5);
    u8x8.print(sv2);
    //ramp rate counter
    if(currentMillis - previousMillis > 1000 / rampRateStep[currentStep-1]) {//seconds counter
      previousMillis = currentMillis;
      counter++;
      setpointRamp = startTemp + counter;
      u8x8.setCursor(6,2);
      u8x8.print(setpointRamp);
      Setpoint1 = setpointRamp;
    }

    if (setpointRamp >= temperatureStep[currentStep-1]) {
      u8x8.setCursor(13,7);
      u8x8.print(temperatureStep[currentStep-1]);
      refLOWState = REFLOW_STATE_STEP;
    }
    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++;
    }
    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:
        u8x8.clear();
        u8x8.setCursor(0,4);
        u8x8.print("REFLOW COMPLETED");
        delay(1000);
    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; 
      u8x8.setCursor(6, 3);
      u8x8.print(tc1);
      u8x8.setCursor(6, 6);
      u8x8.print(tc2);
    }


    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,LOW);  

    else digitalWrite(RelayPin1,HIGH);

    if(Output2 > millis() - windowStartTime) digitalWrite(RelayPin2,LOW);  

    else digitalWrite(RelayPin2,HIGH);
  }
  else
  {
    digitalWrite(RelayPin1, LOW);
    digitalWrite(RelayPin2, LOW);
  }
}

In the time it took to scroll to the bottom of this topic, I found I had grown a moustache. Please learn to post code correctly, using code tags, as described in the forum guide you should have read before posting. Then edit both your posts and put the code tags in. Thankyou.

Sorry i didn't know that code can be tagged :disappointed:

That is a common problem on displays. After a line like this:
device.print(number);
you put a line like this:
`if (number < 10) device.print(' ');'

Then when you go from 10 to 9 you will get "9 " instead of "90". You could also make the digit rught-justified:

  if (number < 10) device.print(' ');
  device.print(number);

Then you would got from "10" to " 9".

You would not know, not having read the forum guide.

Thanks for fixing your posts!

Another way to fix your refresh option problem: change

      u8x8.setCursor(6, 2);
      u8x8.print(sv1);

to

      sprintf(buffer, "%3d", sv1);
      u8x8.drawString(6, 2, buffer);

and declare"buffer"as a global variable:

char buffer[21];

The "%3d" means print a decimal number with a width of 3 characters, padding on the left with spaces as needed.

tried buffer method ..now working ...Thankyou ... Today i attached thermocouple (received today) with max6675 for testing whether its showing temp every second (as per code) ...show only one reading but when pressing ok and cancel button temperature refresh but if I leave it in IDLE menu or RUN menu temp stucks..

i tested max6675 with thermocouple with other sketch it showing temp fine. temp refreshes as normal but not with following sketch

Is it due to memory issue or what or did i miss something or code ?.. serial print shows that codes runs properly to reading temp ie. Input1 and Input2 but values are not refreshing in serial print too.. I am using arduino Nano

/*DUAL LOOP PID CONTROLLER */

#include <Arduino.h>
#include <max6675.h>
#include <Wire.h>
#include <PID_v1.h>
#include <U8x8lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); 
//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

char buffer[21];

//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=1;

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];

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 = 8;  


MAX6675 thermocouple1(thermoCLK, thermoCS, thermoDO);//top heater thermocouple
MAX6675 thermocouple2(thermoCLK2, thermoCS2, thermoDO2);//bottom heater thermocouple
void loadProfile()//this function loads whichever profile currentProfile variable is set to
{

  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);
  u8x8.begin();
  u8x8.setPowerSave(0);
  u8x8.setFont(u8x8_font_5x7_r);
  u8x8.drawString(3,0,"BGA REWORK ");
  u8x8.drawString(6,3,"V1.2");   
  delay(1000);
  u8x8.clear();
  //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(1000);
  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);
//intilization of front menu
  refLOWState=REFLOW_STATE_IDLE;
}
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;
  Input1 = thermocouple1.readCelsius();
  Input2 = thermocouple2.readCelsius();  
  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;
        sprintf(buffer,"%3d",tc1);
    u8x8.drawString(6,3,buffer);
        sprintf(buffer,"%3d",tc2);
    u8x8.drawString(6,6,buffer);
    }

    //Update whole screen only once
    if (updateScreen) {
      u8x8.clear();
      u8x8.drawString(5,0,"IDLE");
      u8x8.drawString(0, 1,"PTN:    STEP:");
      u8x8.drawString(0, 2,"TH SV:");
      u8x8.drawString(0, 3,"TH PV:");
      u8x8.drawString(0, 5,"BH SV:");
      u8x8.drawString(0, 6,"BH PV:");
      u8x8.drawString(0, 7,"TARGET TEMP:");
      updateScreen = false;
    }
        sprintf(buffer,"%3d",sv1);
    u8x8.drawString(6,2,buffer);
    sprintf(buffer,"%3d",sv2);
    u8x8.drawString(6,5,buffer);
        sprintf(buffer,"%3d",currentProfile);
    u8x8.drawString(4,1,buffer);
      sprintf(buffer,"%3d",currentStep);
    u8x8.drawString(13,1,buffer);
      sprintf(buffer,"%3d",temperatureStep[0]);
    u8x8.drawString(13,7,buffer);
      windowStartTime = millis();
    if (upSwitchState == LOW)//if up switch is pressed go to next profile
    {
      currentProfile++;
      delay(100);
      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--;
      delay(100);
      if (currentProfile <= 0)
      {
        currentProfile = 4;
      }
    }
 loadProfile();
    if (editSwitchState == LOW ) //if edit is pressed go to menu
    {
      delay(100);
      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) {
      u8x8.clear();
      u8x8.drawString(0, 0,"PROFILE");
      u8x8.setCursor(8, 0);
      u8x8.print(currentProfile);
      u8x8.drawString(10,0,"EDIT");
      u8x8.drawString(0, 3,"PROFILE STEP:");
      updateScreen = false;
      
      
    }
      u8x8.setCursor(13, 3);
      u8x8.print(profileSteps);
    if (upSwitchState == LOW)
    {
      profileSteps++;
      delay(100);
      if (profileSteps >= 10) {
        profileSteps = 1;
      }
    }
    if (downSwitchState == LOW)
    {
      profileSteps--;
      delay(100);
      if (profileSteps <= 0) {
        profileSteps = 9;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_BOTTOM_HEAT;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_IDLE;
    }

    break;



    
  case REFLOW_STATE_MENU_BOTTOM_HEAT:

   if (updateScreen) {
    u8x8.clear();
    u8x8.drawString(0,0,"BOTTOM HEATER");
    u8x8.drawString(0,3,"TEMP:");
    updateScreen = false;
     
    }
    sprintf(buffer,"%3d",sv2);
    u8x8.drawString(10,3,buffer);
   
    if (upSwitchState == LOW)
    {
      Setpoint2 = Setpoint2 + 10;
      delay(100);
      if (Setpoint2 >= 350)
      {
        Setpoint2 = 350;
      }
    }
    if (downSwitchState == LOW)
    {
      Setpoint2 = Setpoint2 - 10;
      delay(100);
      if (Setpoint2 <= 0)
      {
        Setpoint2 = 0;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_STEP_RAMP;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;


    
    
  case REFLOW_STATE_MENU_STEP_RAMP:

    if (updateScreen) {
        u8x8.clear();
        u8x8.drawString(0, 3,"STEP:");
      sprintf(buffer,"%3d",editStep + 1);
    u8x8.drawString(6,3,buffer);
        u8x8.drawString(0, 6,"RAMP:");
        updateScreen = false;
      
    }
        u8x8.setCursor(6,6);
        u8x8.print(rampRateStep[editStep]);
  
    if (upSwitchState == LOW)
    {
      rampRateStep[editStep] = rampRateStep[editStep] + .25;
      delay(100);
      if (rampRateStep[editStep] >= 9)
      {
        rampRateStep[editStep] = 9;
      }
    }
    if (downSwitchState == LOW)
    {
      rampRateStep[editStep] = rampRateStep[editStep] - .25;
      delay(100);
      if (rampRateStep[editStep] <= .25)
      {
        rampRateStep[editStep] = .00;
      }
    }
    if (okSwitchState == LOW)
    {
      updateScreen = true;
      delay(100);
      if (editStep + 1 == profileSteps){
        editStep = 0;
        refLOWState = REFLOW_STATE_MENU_STEP_TARGET;
      } 
      else {
        editStep++;
      }
    }
    if (cancelSwitchState == LOW)
    {
      updateScreen = true;
      editStep = 0; 
      delay(100);
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;


    
 
   case REFLOW_STATE_MENU_STEP_TARGET:
    if (updateScreen) {
      u8x8.clear();
      u8x8.drawString(0, 3,"STEP:");
      sprintf(buffer,"%3d",editStep + 1);
    u8x8.drawString(6,3,buffer);
      u8x8.drawString(0,6,"TARGET:");
      updateScreen = false;
    }
          sprintf(buffer,"%3d",temperatureStep[editStep]);
    u8x8.drawString(8,6,buffer);      
    if (upSwitchState == LOW)
    {
      temperatureStep[editStep] = temperatureStep[editStep] + 2;
      delay(100);
      if (temperatureStep[editStep] >= 250)
      {
        temperatureStep[editStep] = 250;
      }
    }
    if (downSwitchState == LOW)
    {
      temperatureStep[editStep] = temperatureStep[editStep] - 2;
      delay(100);
      if (temperatureStep[editStep] <= 0)
      {
        temperatureStep[editStep] = 0;
      }   
     
    }

    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      if (editStep + 1 == profileSteps){
        editStep = 0;
        refLOWState = REFLOW_STATE_MENU_STEP_DWELL;
      } 
      else {
        editStep++;
      }
    }  
    if (cancelSwitchState == LOW)
    {
      updateScreen = true;
      delay(100);
      editStep = 0;
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;


    

  case REFLOW_STATE_MENU_STEP_DWELL:

    if (updateScreen) {
      u8x8.clear();
      u8x8.drawString(0, 3,"STEP:");
            sprintf(buffer,"%3d",editStep + 1);
    u8x8.drawString(6,3,buffer);
      u8x8.drawString(0, 6,"DWELL:");
       updateScreen = false;

    }
      sprintf(buffer,"%3d",dwellTimerStep[editStep]);
    u8x8.drawString(8,6,buffer);

    if (upSwitchState == LOW)
    {
      dwellTimerStep[editStep] = dwellTimerStep[editStep] + 5;
      delay(100);
      if (dwellTimerStep[editStep] >= 1000)
      {
        dwellTimerStep[editStep] = 1000;
      }
    }
    if (downSwitchState == LOW)
    {

      dwellTimerStep[editStep] = dwellTimerStep[editStep] - 5;
      delay(100);
      if (dwellTimerStep[editStep] <= 0)
      {
        dwellTimerStep[editStep] = 0;
      }

    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      if (editStep + 1 == profileSteps){

        editStep = 0;
        refLOWState = REFLOW_STATE_MENU_BOTTOM_P;
      } 
      else {
        editStep++;
      }
    }   
    if (cancelSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      editStep = 0;
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;



    

  case REFLOW_STATE_MENU_BOTTOM_P:
    if (updateScreen){
   u8x8.clear();
      u8x8.drawString(0, 0,"BOTTOM HEATER:");
      u8x8.drawString(0, 3,"P=");
      updateScreen = false;
    }
    sprintf(buffer,"%3d",kp2);
    u8x8.drawString(3,3,buffer);

  
    if (upSwitchState == LOW)
    {
      kp2++;
      delay(100);
      if (kp2 >= 500)
      {
        kp2 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      kp2--;
      delay(100);
      if (kp2 <= 0)
      {
        kp2 = 0;
      }

    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_BOTTOM_I;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;


    
  case REFLOW_STATE_MENU_BOTTOM_I:
     if (updateScreen){
      u8x8.clear();
      u8x8.drawString(0, 0,"BOTTOM HEATER:");
      u8x8.drawString(0, 3,"I=");
      updateScreen = false;
     }

        sprintf(buffer,"%3d",ki2);
    u8x8.drawString(3,3,buffer);

    if (upSwitchState == LOW)
    {
      ki2++;
      delay(100);
      if (ki2 >= 500)
      {
        ki2 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      ki2--;
      delay(100);
      if (ki2 <= 0)
      {
        ki2 = 0;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_BOTTOM_D;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      refLOWState = REFLOW_STATE_IDLE;
    }  
    break;


    

  case REFLOW_STATE_MENU_BOTTOM_D:
     if (updateScreen){
      u8x8.clear();
      u8x8.drawString(0, 0,"BOTTOM HEATER:");
     u8x8.drawString(0, 3,"D=");
      updateScreen = false;
     }    
   sprintf(buffer,"%3d",kd2);
    u8x8.drawString(3,3,buffer);
     
    if (upSwitchState == LOW)
    {
      kd2++;
      delay(100);
      if (kd2 >= 500)
      {
        kd2 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      kd2--;
      delay(100);
      if (kd2 <= 0)
      {
        kd2 = 0;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_TOP_P;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      refLOWState = REFLOW_STATE_IDLE;
    }  
    break;


    

  case REFLOW_STATE_MENU_TOP_P:
    if (updateScreen){
      u8x8.clear();
      u8x8.drawString(0, 0,"TOP HEATER:");
      u8x8.drawString(0, 3,"P=");
      updateScreen = false;
    }
       sprintf(buffer,"%3d",kp1);
    u8x8.drawString(3,3,buffer);

    if (upSwitchState == LOW)
    {
      kp1++;
      delay(100);
      if (kp1 >= 500)
      {
        kp1 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      kp1--;
      delay(100);
      if (kp1 <= 0)
      {
        kp1 = 0;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_TOP_I;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;
  case REFLOW_STATE_MENU_TOP_I:
      if (updateScreen){
      u8x8.clear();
      u8x8.drawString(0, 0,"TOP HEATER:");
      u8x8.drawString(0, 3,"I=");
      updateScreen = false;
     }
        sprintf(buffer,"%3d",ki1);
    u8x8.drawString(3,3,buffer);

    if (upSwitchState == LOW)
    {
      ki1++;
      delay(100);
      if (ki1 >= 500)
      {
        ki1 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      ki1--;
      delay(100);
      if (ki1 <= 0)
      {
        ki1 = 0;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_TOP_D;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      refLOWState = REFLOW_STATE_IDLE;
    }  
    break;

  case REFLOW_STATE_MENU_TOP_D:
     if (updateScreen){
      u8x8.clear();
      u8x8.drawString(0, 0,"TOP HEATER:");
      u8x8.drawString(0, 3,"D=");
      updateScreen = false;
     }

             sprintf(buffer,"%3d",kd1);
    u8x8.drawString(3,3,buffer);

    if (upSwitchState == LOW)
    {
      kd1++;
      delay(100);
      if (kd1 >= 500)
      {
        kd1 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      kd1--;
      delay(100);
      if (kd1 <= 0)
      {
        kd1 = 0;
      }

    }
    if (okSwitchState == LOW)
    { 
     u8x8.clear();
     delay(100);
     u8x8.setCursor(0,4);
     u8x8.print("SETTING SAVED");
     delay (2000);
     updateScreen = true;
     refLOWState = REFLOW_STATE_IDLE;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      refLOWState = REFLOW_STATE_IDLE;
    }  
    break;

  case REFLOW_STATE_STEP_RAMP:
    //currentStep = 1;
    if (updateScreen){
      u8x8.clear();
      u8x8.drawString(7, 0,"RUN ");
      u8x8.drawString(0,1, "CURRENT STEP:");
      u8x8.drawString(0, 2,"TH SV:");
      u8x8.drawString(0, 3,"TH PV:");
      u8x8.drawString(0, 5,"BH SV:");
      u8x8.drawString(0, 6,"BH PV:");
      u8x8.drawString(0, 7,"TARGET COMP:");
      updateScreen = false;
      delay(100);
    }
    startTemp = tc1;
  sprintf(buffer,"%3d",currentStep);
    u8x8.drawString(13,1,buffer);
 sprintf(buffer,"%3d",sv2);
    u8x8.drawString(6,5,buffer);
    //ramp rate counter
    if(currentMillis - previousMillis > 1000 / rampRateStep[currentStep-1]) {//seconds counter
      previousMillis = currentMillis;
      counter++;
      setpointRamp = startTemp + counter;
       sprintf(buffer,"%3d",setpointRamp);
    u8x8.drawString(6,2,buffer);
      Setpoint1 = setpointRamp;
    }

    if (setpointRamp >= temperatureStep[currentStep-1]) {
      sprintf(buffer,"%3d",temperatureStep[currentStep-1]);
    u8x8.drawString(13,7,buffer);
      refLOWState = REFLOW_STATE_STEP;
    }
    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++;
    }
    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:
        u8x8.clear();
        u8x8.setCursor(0,4);
        u8x8.print("REFLOW COMPLETED");
        delay(1000);
    refLOWStatus = REFLOW_STATUS_OFF;
    refLOWState = REFLOW_STATE_IDLE;
    updateScreen = true;
    break;
  }


  if (refLOWStatus == REFLOW_STATUS_ON)
  {

    if (millis() > nextRead1)
    {

      // Read thermocouples next sampling period
      nextRead1 += SENSOR_SAMPLING_TIME; 
     sprintf(buffer,"%3d",tc1);
    u8x8.drawString(6,3,buffer);
    sprintf(buffer,"%3d",tc2);
    u8x8.drawString(6,6,buffer);
    
    }


    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,LOW);  

    else digitalWrite(RelayPin1,HIGH);

    if(Output2 > millis() - windowStartTime) digitalWrite(RelayPin2,LOW);  

    else digitalWrite(RelayPin2,HIGH);
  }
  else
  {
    digitalWrite(RelayPin1, LOW);
    digitalWrite(RelayPin2, LOW);
  }
}

Finally code is working flawlessly.
Thankyou members for your kind support.


#include <Arduino.h>
#include <max6675.h>
#include <Wire.h>
#include <PID_v1.h>
#include <U8x8lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* reset=*/ U8X8_PIN_NONE); 

//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//Top Heater
#define RelayPin2 5//Bottom Heater

char buffer[21];

//current editing step pointer
int editStep = 0;

//declaring which pins buttons are connected to
int buzzerPin = 2; 
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 editSwitchState = 0;
int cancelSwitchState = 0;
int okSwitchState = 0;

//profile stuff
byte currentProfile = 1;
int currentStep = 1;
byte profileSteps=1;

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];

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,
}
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;

//For Max 6675
int thermoCLK = 13;
int thermoCS = 10;
int thermoDO = 12;
//For Max 6675
int thermoCLK2 = 7;
int thermoCS2 = 6;
int thermoDO2 = 8;  


MAX6675 thermocouple1(thermoCLK, thermoCS, thermoDO);//top heater thermocouple
MAX6675 thermocouple2(thermoCLK2, thermoCS2, thermoDO2);//bottom heater thermocouple


/*void loadProfile()//this function loads whichever profile currentProfile variable is set to
{

  return;  
}*/
void setup()
{
 
  //setup pins as input for buttons
  Serial.begin(115384);
  pinMode (upSwitchPin, INPUT_PULLUP);
  pinMode (downSwitchPin, INPUT_PULLUP);
  pinMode (editSwitchPin, INPUT_PULLUP);
  pinMode (cancelSwitchPin, INPUT_PULLUP);
  pinMode (okSwitchPin, INPUT_PULLUP);
  pinMode (buzzerPin, OUTPUT);
  u8x8.begin();
  u8x8.setPowerSave(0);
  u8x8.setFont(u8x8_font_5x7_r);
  u8x8.drawString(3,0,"BGA REWORK ");
  u8x8.drawString(6,3,"V1.2");   
  delay(1000);
  u8x8.clear();
  //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(1000);
  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);
//intilization of front menu
  refLOWState=REFLOW_STATE_IDLE;
}
int i=0;
float k=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;
        Input1 = thermocouple1.readCelsius();
        Input2 = thermocouple2.readCelsius();  

    }

    //Update whole screen only once
    if (updateScreen) {
      u8x8.clear();
      u8x8.drawString(5,0,"IDLE");
      u8x8.drawString(0, 1,"PTN:    STEP:  1");
      u8x8.drawString(0, 2,"TH SV:");
      u8x8.drawString(0, 3,"TH PV:");
      u8x8.drawString(0, 5,"BH SV:");
      u8x8.drawString(0, 6,"BH PV:");
      u8x8.drawString(0, 7,"TARGET TEMP:");
      updateScreen = false;
    }
          
            sprintf(buffer,"%3d",tc1);
    u8x8.drawString(6,3,buffer);
        sprintf(buffer,"%3d",tc2);
    u8x8.drawString(6,6,buffer);
        sprintf(buffer,"%3d",sv1);
    u8x8.drawString(6,2,buffer);
    sprintf(buffer,"%3d",sv2);
    u8x8.drawString(6,5,buffer);
        sprintf(buffer,"%3d",currentProfile);
    u8x8.drawString(4,1,buffer);
      sprintf(buffer,"%3d",currentStep);
    u8x8.drawString(13,1,buffer);
      sprintf(buffer,"%3d",temperatureStep[0]);
    u8x8.drawString(13,7,buffer);
      windowStartTime = millis();
    if (upSwitchState == LOW)//if up switch is pressed go to next profile
    {
      currentProfile++;
      delay(50);
      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--;
      delay(50);
      if (currentProfile <= 0)
      {
        currentProfile = 4;
      }
    }

    if (editSwitchState == LOW ) //if edit is pressed go to menu
    {
      delay(100);
      refLOWState = REFLOW_STATE_MENU_STEPS;
      //update next screen
      updateScreen = true;
    }

    if (okSwitchState == LOW)
    {
      //update next screen
      updateScreen = true;
      refLOWStatus = REFLOW_STATUS_ON;
          k=millis();
      refLOWState = REFLOW_STATE_STEP_RAMP;
    }

    break;



 
  case REFLOW_STATE_MENU_STEPS:
    if (updateScreen) {
      u8x8.clear();
      u8x8.drawString(0, 0,"PROFILE");
      u8x8.setCursor(8, 0);
      u8x8.print(currentProfile);
      u8x8.drawString(10,0,"EDIT");
      u8x8.drawString(0, 3,"PROFILE STEP:");
      updateScreen = false;
      
      
    }
      u8x8.setCursor(13, 3);
      u8x8.print(profileSteps);
    if (upSwitchState == LOW)
    {
      profileSteps++;
      delay(50);
      if (profileSteps >= 10) {
        profileSteps = 1;
      }
    }
    if (downSwitchState == LOW)
    {
      profileSteps--;
      delay(50);
      if (profileSteps <= 0) {
        profileSteps = 9;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_BOTTOM_HEAT;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_IDLE;
    }

    break;



    
  case REFLOW_STATE_MENU_BOTTOM_HEAT:

   if (updateScreen) {
    u8x8.clear();
    u8x8.drawString(0,0,"BOTTOM HEATER");
    u8x8.drawString(0,3,"TEMP:");
    updateScreen = false;
     
    }
    sprintf(buffer,"%3d",sv2);
    u8x8.drawString(10,3,buffer);
   
    if (upSwitchState == LOW)
    {
      Setpoint2 = Setpoint2 + 10;
      delay(50);
      if (Setpoint2 >= 350)
      {
        Setpoint2 = 350;
      }
    }
    if (downSwitchState == LOW)
    {
      Setpoint2 = Setpoint2 - 10;
      delay(50);
      if (Setpoint2 <= 0)
      {
        Setpoint2 = 0;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_STEP_RAMP;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;


    
    
  case REFLOW_STATE_MENU_STEP_RAMP:

    if (updateScreen) {
        u8x8.clear();
        u8x8.drawString(0, 3,"STEP:");
      sprintf(buffer,"%3d",editStep + 1);
    u8x8.drawString(6,3,buffer);
        u8x8.drawString(0, 6,"RAMP:");
        updateScreen = false;
      
    }
        u8x8.setCursor(6,6);
        u8x8.print(rampRateStep[editStep]);
  
    if (upSwitchState == LOW)
    {
      rampRateStep[editStep] = rampRateStep[editStep] + .05;
      delay(50);
      if (rampRateStep[editStep] >= 9)
      {
        rampRateStep[editStep] = 9;
      }
    }
    if (downSwitchState == LOW)
    {
      rampRateStep[editStep] = rampRateStep[editStep] - .05;
      delay(50);
      if (rampRateStep[editStep] <= .05)
      {
        rampRateStep[editStep] = .05;
      }
    }
    if (okSwitchState == LOW)
    {
      updateScreen = true;
      delay(100);
      if (editStep + 1 == profileSteps){
        editStep = 0;
        refLOWState = REFLOW_STATE_MENU_STEP_TARGET;
      } 
      else {
        editStep++;
      }
    }
    if (cancelSwitchState == LOW)
    {
      updateScreen = true;
      editStep = 0; 
      delay(100);
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;


    
 
   case REFLOW_STATE_MENU_STEP_TARGET:
    if (updateScreen) {
      u8x8.clear();
      u8x8.drawString(0, 3,"STEP:");
      sprintf(buffer,"%3d",editStep + 1);
    u8x8.drawString(6,3,buffer);
      u8x8.drawString(0,6,"TARGET:");
      updateScreen = false;
    }
          sprintf(buffer,"%3d",temperatureStep[editStep]);
    u8x8.drawString(8,6,buffer);      
    if (upSwitchState == LOW)
    {
      temperatureStep[editStep] = temperatureStep[editStep] + 2;
      delay(50);
      if (temperatureStep[editStep] >= 250)
      {
        temperatureStep[editStep] = 250;
      }
    }
    if (downSwitchState == LOW)
    {
      temperatureStep[editStep] = temperatureStep[editStep] - 2;
      delay(50);
      if (temperatureStep[editStep] <= 0)
      {
        temperatureStep[editStep] = 0;
      }   
     
    }

    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      if (editStep + 1 == profileSteps){
        editStep = 0;
        refLOWState = REFLOW_STATE_MENU_STEP_DWELL;
      } 
      else {
        editStep++;
      }
    }  
    if (cancelSwitchState == LOW)
    {
      updateScreen = true;
      delay(100);
      editStep = 0;
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;


    

  case REFLOW_STATE_MENU_STEP_DWELL:

    if (updateScreen) {
      u8x8.clear();
      u8x8.drawString(0, 3,"STEP:");
            sprintf(buffer,"%3d",editStep + 1);
    u8x8.drawString(6,3,buffer);
      u8x8.drawString(0, 6,"DWELL:");
       updateScreen = false;

    }
      sprintf(buffer,"%3d",dwellTimerStep[editStep]);
    u8x8.drawString(8,6,buffer);

    if (upSwitchState == LOW)
    {
      dwellTimerStep[editStep] = dwellTimerStep[editStep] + 1;
      delay(50);
      if (dwellTimerStep[editStep] >= 1000)
      {
        dwellTimerStep[editStep] = 1000;
      }
    }
    if (downSwitchState == LOW)
    {

      dwellTimerStep[editStep] = dwellTimerStep[editStep] - 1;
      delay(50);
      if (dwellTimerStep[editStep] <= 0)
      {
        dwellTimerStep[editStep] = 0;
      }

    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      if (editStep + 1 == profileSteps){

        editStep = 0;
        refLOWState = REFLOW_STATE_MENU_BOTTOM_P;
      } 
      else {
        editStep++;
      }
    }   
    if (cancelSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      editStep = 0;
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;



    

  case REFLOW_STATE_MENU_BOTTOM_P:
    if (updateScreen){
   u8x8.clear();
      u8x8.drawString(0, 0,"BOTTOM HEATER:");
      u8x8.drawString(0, 3,"P=");
      updateScreen = false;
    }
    sprintf(buffer,"%3d",kp2);
    u8x8.drawString(3,3,buffer);

  
    if (upSwitchState == LOW)
    {
      kp2++;
      delay(50);
      if (kp2 >= 500)
      {
        kp2 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      kp2--;
      delay(50);
      if (kp2 <= 0)
      {
        kp2 = 0;
      }

    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_BOTTOM_I;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;


    
  case REFLOW_STATE_MENU_BOTTOM_I:
     if (updateScreen){
      u8x8.clear();
      u8x8.drawString(0, 0,"BOTTOM HEATER:");
      u8x8.drawString(0, 3,"I=");
      updateScreen = false;
     }

        sprintf(buffer,"%3d",ki2);
    u8x8.drawString(3,3,buffer);

    if (upSwitchState == LOW)
    {
      ki2++;
      delay(50);
      if (ki2 >= 500)
      {
        ki2 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      ki2--;
      delay(50);
      if (ki2 <= 0)
      {
        ki2 = 0;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_BOTTOM_D;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      refLOWState = REFLOW_STATE_IDLE;
    }  
    break;


    

  case REFLOW_STATE_MENU_BOTTOM_D:
     if (updateScreen){
      u8x8.clear();
      u8x8.drawString(0, 0,"BOTTOM HEATER:");
     u8x8.drawString(0, 3,"D=");
      updateScreen = false;
     }    
   sprintf(buffer,"%3d",kd2);
    u8x8.drawString(3,3,buffer);
     
    if (upSwitchState == LOW)
    {
      kd2++;
      delay(50);
      if (kd2 >= 500)
      {
        kd2 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      kd2--;
      delay(50);
      if (kd2 <= 0)
      {
        kd2 = 0;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_TOP_P;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      refLOWState = REFLOW_STATE_IDLE;
    }  
    break;


    

  case REFLOW_STATE_MENU_TOP_P:
    if (updateScreen){
      u8x8.clear();
      u8x8.drawString(0, 0,"TOP HEATER:");
      u8x8.drawString(0, 3,"P=");
      updateScreen = false;
    }
       sprintf(buffer,"%3d",kp1);
    u8x8.drawString(3,3,buffer);

    if (upSwitchState == LOW)
    {
      kp1++;
      delay(50);
      if (kp1 >= 500)
      {
        kp1 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      kp1--;
      delay(50);
      if (kp1 <= 0)
      {
        kp1 = 0;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_TOP_I;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_IDLE;
    }
    break;
  case REFLOW_STATE_MENU_TOP_I:
      if (updateScreen){
      u8x8.clear();
      u8x8.drawString(0, 0,"TOP HEATER:");
      u8x8.drawString(0, 3,"I=");
      updateScreen = false;
     }
        sprintf(buffer,"%3d",ki1);
    u8x8.drawString(3,3,buffer);

    if (upSwitchState == LOW)
    {
      ki1++;
      delay(50);
      if (ki1 >= 500)
      {
        ki1 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      ki1--;
      delay(50);
      if (ki1 <= 0)
      {
        ki1 = 0;
      }
    }
    if (okSwitchState == LOW)
    {
      delay(100);
      updateScreen = true;
      refLOWState = REFLOW_STATE_MENU_TOP_D;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      refLOWState = REFLOW_STATE_IDLE;
    }  
    break;

  case REFLOW_STATE_MENU_TOP_D:
     if (updateScreen){
      u8x8.clear();
      u8x8.drawString(0, 0,"TOP HEATER:");
      u8x8.drawString(0, 3,"D=");
      updateScreen = false;
     }

             sprintf(buffer,"%3d",kd1);
    u8x8.drawString(3,3,buffer);

    if (upSwitchState == LOW)
    {
      kd1++;
      delay(50);
      if (kd1 >= 500)
      {
        kd1 = 500;
      }
    }
    if (downSwitchState == LOW)
    {
      kd1--;
      delay(50);
      if (kd1 <= 0)
      {
        kd1 = 0;
      }

    }
    if (okSwitchState == LOW)
    { 
     u8x8.clear();
     delay(100);
     u8x8.setCursor(0,4);
     u8x8.print("SETTING SAVED");
     delay (2000);
     updateScreen = true;
     refLOWState = REFLOW_STATE_IDLE;
    }
    if (cancelSwitchState == LOW)
    {
      delay(100);
      refLOWState = REFLOW_STATE_IDLE;
    }  
    break;

  case REFLOW_STATE_STEP_RAMP:
    //currentStep = 1;
    if (updateScreen){
      u8x8.clear();
      u8x8.drawString(7, 0,"RUN ");
      u8x8.drawString(0,1, "CURRENT STEP:");
      u8x8.drawString(0, 2,"TH SV:");
      u8x8.drawString(0, 3,"TH PV:");
      u8x8.drawString(0, 5,"BH SV:");
      u8x8.drawString(0, 6,"BH PV:");
      u8x8.drawString(0, 7,"TARGET COMP:");
      updateScreen = false;
      delay(100);
    }
    startTemp = tc1;
    Serial.print((millis()-k)/1000);
     Serial.print(",");
     Serial.print(tc1);
      Serial.print(",");
     Serial.print(sv1);
     Serial.print("\r\n");
      Serial.println("");
     
  sprintf(buffer,"%3d",currentStep);
    u8x8.drawString(13,1,buffer);
 sprintf(buffer,"%3d",sv2);
    u8x8.drawString(6,5,buffer);
    //ramp rate counter
    if(currentMillis - previousMillis > 1000 / rampRateStep[currentStep-1]) {//seconds counter
      previousMillis = currentMillis;
      counter++;
      setpointRamp = startTemp + counter;
       sprintf(buffer,"%3d",setpointRamp);
    u8x8.drawString(6,2,buffer);
      Setpoint1 = setpointRamp;
    }

    if (setpointRamp >= temperatureStep[currentStep-1]) {
      sprintf(buffer,"%3d",temperatureStep[currentStep-1]);
    u8x8.drawString(13,7,buffer);
      refLOWState = REFLOW_STATE_STEP;
    }
    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++;
    }
    if (counter == dwellTimerStep[currentStep-1]) {
      counter = 0;
      setpointRamp = 0;
      if (currentStep == profileSteps) {
        refLOWState = REFLOW_STATE_COMPLETE;
      }
      else {
        if(currentStep < profileSteps){
           currentStep++;
        refLOWState = REFLOW_STATE_STEP_RAMP; /////////////////////////??????????
        }
        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:
        u8x8.clear();
        u8x8.setCursor(0,4);
        u8x8.print("REFLOW COMPLETED");
        delay(5000);
    refLOWStatus = REFLOW_STATUS_OFF;
    refLOWState = REFLOW_STATE_IDLE;
    updateScreen = true;
    break;
  }


  if (refLOWStatus == REFLOW_STATUS_ON)
  {

    if (millis() > nextRead1)
    {

      // Read thermocouples next sampling period
      nextRead1 += SENSOR_SAMPLING_TIME; 
        Input1 = thermocouple1.readCelsius();
        Input2 = thermocouple2.readCelsius();  
    

    }


    sprintf(buffer,"%3d",tc1);
    u8x8.drawString(6,3,buffer);
    sprintf(buffer,"%3d",tc2);
    u8x8.drawString(6,6,buffer);

    
    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);
  }
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.