Returning to while loop after the interrupt has been called

I am creating a programme to control temperature through the use of a stepper motor. I have the system running fine until the very end. I then want it to return to the start of the while loop after i have called the interrupt to check the temperature. The issue is that when i operate the motor i can no longer check the temperature. Any advise would be appreciated!

#include “mbed.h”
#include “TextLCD.h”

// Declarations

BusOut Steppermotor(p11, p12, p13, p14); // (IN1) - (IN2) - (IN3) - (IN4)
AnalogIn LM35(p15); // Temperature Sensor
DigitalOut GreenLED(p7);
DigitalOut RedLED(p5);
DigitalOut Orange_LED_flash(p6);
InterruptIn Button(p25); // Temperature check
InterruptIn Button2(p24); // Motor Control - Window open
InterruptIn Button3(p23); // Motor control - Window close
Timeout Response;

TextLCD lcd(p21, p22, p27, p28, p29, p30, TextLCD::LCD16x2); // LCD Display Wiring

// variable declartations

float tempC=0; // Temperature in celcius
float target_temp = 20; // Target temperature
int step = 0; // variable integer values for the system.
int dir=1;
int i=0;

void return_to_start(){
if(tempC<=target_temp)
{
GreenLED = 1;
wait(3);
}

    else if(tempC>target_temp){
        GreenLED = 0;
        Orange_LED_flash = !Orange_LED_flash;
        wait(0.5);
        lcd.cls();
        wait(0.5);
        lcd.printf("Window requires\n adjustment\n");
        lcd.cls();
        }
        }

void Temp_check() { // Temperature check interrupt
tempC=LM35.read();
tempC=(tempC3.3100); //LM35 Thermistor

    // Display temperature
    
    lcd.locate(0,0);
    lcd.printf("cT      sT");
    lcd.locate(0,1);
    
    // Display current and target temperature
     
    lcd.printf("%.1f    %.1f",tempC,target_temp);
    wait(5);
    lcd.cls();
    }

void Motor_control(){

    i=56;                           // The amount of times the loop will run, in this case, 56.
while(1){                           
                                    
    if(i>56) {GreenLED=0; RedLED=0;} 
                                    
    if(Button3==1)  {i=0;dir=0;}   // These are the variable inputs that will
    if(Button2==1)  {i=0;dir=1;}   // determine the movement of the motor
    
    while (i<=56)   {
        switch(step)
        {
            case 0: Steppermotor = 0x1; break; //0001 
            case 1: Steppermotor = 0x2; break; //0010
            case 2: Steppermotor = 0x4; break; //0100
            case 3: Steppermotor = 0x8; break; //1000
            
            
            default: Steppermotor = 0x0; break; //0000
        }
            
        if(dir==1) {step++;} else {step--;}
        if(step>3) {step=0;}
        if(step<0) {step=3;}
            
        if(dir==1) {GreenLED=1; RedLED=0;} else {GreenLED=0; RedLED=1;}
            
        wait(0.005);    //speedooo
        i++;
    
    }
}

}

int main(){

Button.rise(&Temp_check); // Interrups
Button2.rise(&Motor_control);
Button3.rise(&Motor_control);

// welcome message

lcd.cls(); 
wait(2);

GreenLED = 1;
wait(0.5);
GreenLED = 0;
wait(0.5);
GreenLED = 1;
wait(0.5);
GreenLED = 0;
wait(0.5);
GreenLED = 1;
wait(0.5);
GreenLED = 0;
wait(3);

lcd.printf("AD Automated\nControl Systems\n");
wait(3);
lcd.cls();
wait(3);
lcd.printf("Temp. ready for\n assesment \n");
wait(3);
lcd.cls();

while(1){
    
    if(tempC<=target_temp)
    {
         GreenLED = 1;
         wait(3);
        }
        
    else if(tempC>target_temp){
        GreenLED = 0;
        Orange_LED_flash = !Orange_LED_flash;
        wait(0.5);
        lcd.cls();
        wait(0.5);
        lcd.printf("Window requires\n adjustment\n");
        lcd.cls();
        }
        Response.attach(&return_to_start,2.0);{
            }
            }
            }

Hello,

please be so kind and use these 3 ``` symbols before and after your code for correct code formatting for better view.

Of course because you have infinite loop inside your handler for rise event - Motor_control(), so your program is imprisoned in ISR forever.

BR, Jan

JohnnyK, thank you very much. This has solved the issue. I’m in my first year of college so i’m new to this.

Much appreciated .