 static Joystick joystick(JOYSTICK_SW, JOYSTICK_X, JOYSTICK_Y);
 static Pano pano(horiz_motor, vert_motor, camera, HORIZ_EN, VERT_EN);
 
+// these variables are modified by the menu
+volatile int focal, horiz, vert, shutter, pre_shutter, running, orientation, aspect, shots, motors_enable;
+volatile int stop_running = false;
+
+void button_click(){
+    stop_running = true;
+}
+
 const int rows = 6;
 
 void setup() {

        display.print(F("vert = "));
        display.println(pano.vert_position);
        display.display();
        running = pano.next();
        if (!running){
            pano.end();
            display.println(F("end"));
            display.display();
            delay(5000);
            menu.open();
            handleEvent(EVENT_NONE);
        }

}

void loop() {
    if (!running){
        int event = joystick.read();
        if (event){
            handleEvent(event);
            delay(100);

            if (motors_enable){
                pano.motorsOn();
            } else {
                pano.motorsOff();
            }

            if (running){   // pano was just started via Menu
                menu.cancel(); // go back to main menu to avoid re-triggering
                motors_enable = true;
                menu.sync();

                display.clearDisplay();
                display.setCursor(0,0);
                display.print(F("Start "));
                display.display();

                pano.setFocalLength(focal);
                pano.setFOV(horiz, vert);
                pano.setShutter(shutter, pre_shutter);
                pano.setShots(shots);

                stop_running = false;
                attachInterrupt(digitalPinToInterrupt(JOYSTICK_SW), button_click, FALLING);

                pano.start();
            }
        }
    } else {   // pano is in progress
        display.clearDisplay();
        display.setCursor(0,0);
        display.println(F("running\n"));
