code optimization sub-function

Hello,

I'm trying to optimize my code by introducing sub-function.

void FlapsScreenTouch()
{
  bool down = Touch_getXY();

    FLAP1.press(down && FLAP1.contains(pixel_x, pixel_y));
    FLAP2.press(down && FLAP2.contains(pixel_x, pixel_y));
    FLAP3.press(down && FLAP3.contains(pixel_x, pixel_y));
    FLAP4.press(down && FLAP4.contains(pixel_x, pixel_y));
    FLAP5.press(down && FLAP5.contains(pixel_x, pixel_y));
    MENU.press(down && MENU.contains(pixel_x, pixel_y));
    
     if (FLAP1.justPressed())
      {        
              
              flap11=!flap11;
              VacuumOperation();
              if(flap11 == true)
               {
                Serial.println("vacuum1 ON");
                digitalWrite(OUT_RELAY_0, LOW);
                delay(1500);
                digitalWrite(OUT_RELAY_1, LOW);
                delay( 8000);
                digitalWrite(OUT_RELAY_1, HIGH);
                delay(1500);
                digitalWrite(OUT_RELAY_0, HIGH);
                }else
                {
                  Serial.println("vacuum1 OFF");
                  digitalWrite(OUT_RELAY_1, LOW);
                  delay(5000);
                  digitalWrite(OUT_RELAY_1, HIGH);
                }
                FlapsScreenDraw();
                
                
      }

      if (FLAP2.justPressed())
      {        
          flap22=!flap22;
          VacuumOperation();
          if(flap22 == true)
               {
                Serial.println("vacuum2 ON");
                digitalWrite(OUT_RELAY_0, LOW);
                delay(1500);
                digitalWrite(OUT_RELAY_2, LOW);
                delay( 8000);
                digitalWrite(OUT_RELAY_2, HIGH);
                delay(1500);
                digitalWrite(OUT_RELAY_0, HIGH);
                Serial.println("vacuum2 finished");
                }else
                {
                  Serial.println("vacuum2 OFF");
                  digitalWrite(OUT_RELAY_2, LOW);
                  delay(5000);
                  digitalWrite(OUT_RELAY_2, HIGH);
                  Serial.println("vacuum2 finished");
                } 
                FlapsScreenDraw();
      }

      if (FLAP3.justPressed())
      {        
          flap33=!flap33;
          VacuumOperation();
          if(flap33 == true)
               {
                Serial.println("vacuum3 ON");
                digitalWrite(OUT_RELAY_0, LOW);
                delay(1500);
                digitalWrite(OUT_RELAY_3, LOW);
                delay( 8000);
                digitalWrite(OUT_RELAY_3, HIGH);
                delay(1500);
                digitalWrite(OUT_RELAY_0, HIGH);
                Serial.println("vacuum3 finished");
                }else
                {
                  Serial.println("vacuum3 OFF");
                  digitalWrite(OUT_RELAY_3, LOW);
                  delay(5000);
                  digitalWrite(OUT_RELAY_3, HIGH);
                  Serial.println("vacuum3 finished");
                }
                FlapsScreenDraw();    
      }

      if (FLAP4.justPressed())
      {        
          flap44=!flap44;
          VacuumOperation();
          if(flap44 == true)
               {
                Serial.println("vacuum4 ON");
                digitalWrite(OUT_RELAY_0, LOW);
                delay(1500);
                digitalWrite(OUT_RELAY_4, LOW);
                delay( 8000);
                digitalWrite(OUT_RELAY_4, HIGH);
                delay(1500);
                digitalWrite(OUT_RELAY_0, HIGH);
                Serial.println("vacuum4 finished");
                }else
                {
                  Serial.println("vacuum4 OFF");
                  digitalWrite(OUT_RELAY_4, LOW);
                  delay(5000);
                  digitalWrite(OUT_RELAY_4, HIGH);
                  Serial.println("vacuum4 finished");
                }
                FlapsScreenDraw();   
      }

      if (FLAP5.justPressed())
      {        
          flap55=!flap55;
          VacuumOperation();
          if(flap55 == true)
               {
                Serial.println("vacuum5 ON");
                digitalWrite(OUT_RELAY_0, LOW);
                delay(1500);
                digitalWrite(OUT_RELAY_5, LOW);
                delay( 8000);
                digitalWrite(OUT_RELAY_5, HIGH);
                delay(1500);
                digitalWrite(OUT_RELAY_0, HIGH);
                Serial.println("vacuum5 finished");
                }else
                {
                  Serial.println("vacuum5 OFF");
                  digitalWrite(OUT_RELAY_5, LOW);
                  delay(5000);
                  digitalWrite(OUT_RELAY_5, HIGH);
                  Serial.println("vacuum5 finished");
                }
                FlapsScreenDraw();    
      }

      if (MENU.justPressed())
      {
        MENU.drawButton(true);
        HomeScreenDraw();
        page=0;
      }
     
}

As I'm basically repeating 5 times same code with different variables, I wanted to do it once by doing below and than calling this function 5 times configuring my button and relay. Easier to change settings as I would do it in one place, not 5...
It however spits this error

HVAC-TFT-STEPPER-RELAY-3TEMP_v1:641:15: error: 'class String' has no member named 'justPressed'

if (FLAPN.justPressed()) //FLAP1

^~~~~~~~~~~

exit status 1

'class String' has no member named 'justPressed'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

void flapRUN ( String FLAPN, boolean flapNN,  byte RelayN, String flap_name)
{
    if (FLAPN.justPressed()) //FLAP1
    {        
        flapNN=!flapNN; //flap11
        VacuumOperation();
        if(flapNN == true) //flap11
        {
            Serial.print("vacuum");
            Serial.print(flap_name);
            Serial.println("ON");
            digitalWrite(OUT_RELAY_0, LOW);
            delay(1500);
            digitalWrite(RelayN, LOW); //OUT_RELAY_1
            delay( 8000);
            digitalWrite(RelayN, HIGH);//OUT_RELAY_1
            delay(1500);
            digitalWrite(OUT_RELAY_0, HIGH);
        }
        else
        {
            Serial.print("vacuum");
            Serial.print(flap_name);
            Serial.println("OFF");
            digitalWrite(RelayN, LOW);//OUT_RELAY_1
            delay(5000);
            digitalWrite(RelayN, HIGH);//OUT_RELAY_1
        }
    }
}

I would call my level of programming as beginner... Early beginner. I can paste the whole program, but don't think rest is relevant. It all works without my poor atempt of optimization of code.

thanks,
regards

You have FLAPN declared as a String. The String class has no member justPressed.

What type are FLAP1, FLAP2, FLAP3, FLAP4, and FLAP5?

I’m using “Adafruit_GFX_Button” from library <Adafruit_GFX.h>

so I have it on the beginning :

Adafruit_GFX_Button FLAPN, FLAPS, STEPPER, FLAP1, FLAP2, FLAP3, FLAP4, FLAP5, MENU, StepperScrollButton, RUN;

Hopefully, this answer the questions or I’m a total begginer

So your function definition should look like this:

void flapRUN ( Adafruit_GFX_Button& FLAPN, boolean flapNN,  byte RelayN, String flap_name)

DANG!!

Your question was actually the asnwer as I had an idea a second after my reply to do same what you just wrote!

Came back to say I solved it and you confirmed that !

Thanks a lot :slight_smile:

do I need that "&" ? it works without it

dremmettbrown:
do I need that "&" ? it works without it

The & means pass by reference so the whole object is not copied to the stack. If you are running low on SRAM it might prevent a stack overflow and will save a little processing time.

danke!! Kudos for you!

one more question,

if I want to use value from variable "flapNN" in other function (FlapsScreenDraw), how do I specify that?
How do I update global variable?

I have a function FlapsScreenDraw called in fucntion that we were discussing...

void flapRUN ( Adafruit_GFX_Button FLAPN, boolean flapNN,  byte RelayN, String flap_name)
{
    if (FLAPN.justPressed()) //FLAP1
    {   
        Serial.println(flapNN);  
        flapNN =! flapNN; //flap11
        Serial.println(flapNN);
        VacuumOperation();
        if(flapNN == true) //flap11
        {
            Serial.print("vacuum ");
            Serial.print(flap_name);
            Serial.println(" ON");
            digitalWrite(OUT_RELAY_0, LOW);
            delay(1500);
            digitalWrite(RelayN, LOW); //OUT_RELAY_1
            delay( 8000);
            digitalWrite(RelayN, HIGH);//OUT_RELAY_1
            delay(1500);
            digitalWrite(OUT_RELAY_0, HIGH);
        }
        else
        {
            Serial.print("vacuum");
            Serial.print(flap_name);
            Serial.println("OFF");
            digitalWrite(RelayN, LOW);//OUT_RELAY_1
            delay(5000);
            digitalWrite(RelayN, HIGH);//OUT_RELAY_1
        }
       
       FlapsScreenDraw();  
    }
   
}

read a lot and solved it by adding “&” before my variable

void flapRUN ( Adafruit_GFX_Button FLAPN, boolean &flapNN,  byte RelayN, String flap_name)

thanks!

How do I update global variable?

If the variable is global then changing it anywhere in the program will update it and the value will be available anywhere in the program

void flapRUN ( Adafruit_GFX_Button FLAPN, boolean &flapNN,  byte RelayN, String flap_name)

If the flapNN variable is global then you do not need to pass it to functions - see the previous paragraph

Do you know what the & before a variable name in a function parameter list means ?

I run my function 5 times with different inputs :

flapRUN(FLAP1, flap11,  OUT_RELAY_1, "flap1");
flapRUN(FLAP2, flap22,  OUT_RELAY_2, "flap2");
flapRUN(FLAP3, flap33,  OUT_RELAY_3, "flap3");
flapRUN(FLAP4, flap44,  OUT_RELAY_4, "flap4");
flapRUN(FLAP5, flap55,  OUT_RELAY_5, "flap5");

despite declaring flapNN globally, it would not update value after running my function:

boolean flap11=false, flap22=false, flap33=false, flap44=false, flap55=false;
void flapRUN ( Adafruit_GFX_Button FLAPN, boolean &flapNN,  byte RelayN, String flap_name)
{
    if (FLAPN.justPressed()) //FLAP1
    {   
        Serial.println(flapNN);  
        flapNN =! flapNN; //flap11
        Serial.println(flapNN);
        VacuumOperation();
        if(flapNN == true) //flap11
        {
            Serial.print("vacuum ");
            Serial.print(flap_name);
            Serial.println(" ON");
            digitalWrite(OUT_RELAY_0, LOW);
            delay(1500);
            digitalWrite(RelayN, LOW); //OUT_RELAY_1
            delay( 8000);
            digitalWrite(RelayN, HIGH);//OUT_RELAY_1
            delay(1500);
            digitalWrite(OUT_RELAY_0, HIGH);
            
        }
        else
        {
            Serial.print("vacuum");
            Serial.print(flap_name);
            Serial.println("OFF");
            digitalWrite(RelayN, LOW);//OUT_RELAY_1
            delay(5000);
            digitalWrite(RelayN, HIGH);//OUT_RELAY_1
            
        }
        
       FlapsScreenDraw(); 
    }
   
}

as subfunction in that function FlapsScreenDraw() was not getting correct value from it parent function

void FlapsScreenDraw()
{
  tft.fillScreen(BLACK);
  tft.setTextColor(YELLOW);
  tft.setTextSize(2);
  tft.setCursor(10, 10);
  tft.println("REINSCH ENGINEERING - HVAC test v1");
  tft.setCursor(10,35);
  tft.println("Press flap to activate.");
 
  FLAP1.initButton(&tft, 100, 140, 100, 70, YELLOW, RED, BLACK, "FLAP1", 2);
  FLAP2.initButton(&tft, 240, 140, 100, 70, YELLOW, RED, BLACK, "FLAP2", 2);
  FLAP3.initButton(&tft, 380, 140, 100, 70, YELLOW, RED, BLACK, "FLAP3", 2);
  FLAP4.initButton(&tft, 100, 230, 100, 70, YELLOW, RED, BLACK, "FLAP4", 2);
  FLAP5.initButton(&tft, 240, 230, 100, 70, YELLOW, RED, BLACK, "FLAP5", 2);
  MENU.initButton(&tft, 420, 270, 100, 70, YELLOW, YELLOW, BLACK, "MENU", 2);
  
  MENU.drawButton(false);
  
  Flap11();
  Flap22();
  Flap33();
  Flap44();
  Flap55();
  
}

I did read a bit more about & . Main reason I've used it was due to some other topic suggested it.

If my understanding about how I've solved it is wrong (despite it is working) I would appreciate explanation what I did wrong previously and what I did now and how is that different to what I'm saying I did. Hope it makes sense?

Please post a complete sketch that illustrates the problem otherwise any replies will be guesswork

first part of code

//--------------------STEPPER MOTOR SETUP-------------------

// AccelStepper - Version: Latest 
#include <AccelStepper.h>
#include <MultiStepper.h>

// Motor pin definitions
#define HALFSTEP 8
#define motorPin1  24     // IN1 on the ULN2003 driver 1 8
#define motorPin2  26     // IN2 on the ULN2003 driver 1 9
#define motorPin3  28     // IN3 on the ULN2003 driver 1 10
#define motorPin4  30     // IN4 on the ULN2003 driver 1 11

// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);



//-------------------------------- END OF STEPPER ----------------------------

// ------------------------------TFT SCREEN------------------------------------
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>

#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSerif12pt7b.h>
#include <FreeDefaultFonts.h>

const int XP = 8, XM = A2, YP = A3, YM = 9; 
const int TS_LEFT = 954, TS_RT = 95, TS_TOP = 915, TS_BOT = 126;

#define MINPRESSURE 400
#define MAXPRESSURE 1000

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0  
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 264);

Adafruit_GFX_Button FLAPS, STEPPER, FLAP1, FLAP2, FLAP3, FLAP4, FLAP5, MENU, StepperScrollButton, RUN;

int pixel_x, pixel_y;     //Touch_getXY() updates global vars
bool Touch_getXY(void)
{

    TSPoint p = ts.getPoint();
    pinMode(YP, OUTPUT);      //restore shared pins
    pinMode(XM, OUTPUT);
    digitalWrite(YP, HIGH);   //because TFT control pins
    digitalWrite(XM, HIGH);
    bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
    if (pressed) {
        pixel_x = map(p.y, TS_LEFT, TS_RT, 0, 480); //.kbv makes sense to me
        pixel_y = map(p.x, TS_TOP, TS_BOT, 0, 320);
    }
    return pressed;
}


// -------------------------TEMPERATURE SENSOR SETUP--------------------------
#include <OneWire.h> // First we include the libraries
#include <DallasTemperature.h> // First we include the libraries

//Temp sensor pin setup
#define ONE_WIRE_BUS_PIN 22 // Data wire is plugged into pin 22 on the Arduino

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);  // Setup a oneWire instance to communicate with any OneWire devices 

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.

// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
DeviceAddress SensCabin = { 0x28, 0xFF, 0xD0, 0x72, 0x60, 0x17, 0x05, 0xA1 };
DeviceAddress SensIntake = { 0x28, 0xFF, 0x8B, 0x44, 0x60, 0x17, 0x05, 0x05 };
DeviceAddress SensCold = { 0x28, 0xFF, 0xA1, 0x8C, 0x60, 0x17, 0x03, 0xB8 };
DeviceAddress SensWarm = { 0x28, 0xFF, 0xDC, 0x71, 0x60, 0x17, 0x05, 0x08 };

// --------------------------END of TEMPERATURE SENSOR SETUP-----------------------------

String odebraneDane = "";
int stepper1pozycja = 0;
int StepperScroll = 40;
char page = 0;
bool busy = false;
boolean flap11=false, flap22=false, flap33=false, flap44=false, flap55=false; 
unsigned long vacuumtime = 0;
unsigned long TempReadTime = 0;
char RUNstepper = 0;
boolean flapNN;

//--------------------------RELAYS for SOLENOID ----------------------------------------------


const int OUT_RELAY_0 = 46;
const int OUT_RELAY_1 = 44;
const int OUT_RELAY_2 = 42;
const int OUT_RELAY_3 = 40;
const int OUT_RELAY_4 = 38;
const int OUT_RELAY_5 = 36;
const int OUT_RELAY_6 = 34;
const int OUT_RELAY_7 = 32;

//---------------------------------------------------------------------------------------------

//---------------------------------------SETUP LOOP -------------------------------------------

void setup()
{
  //--------------stepper setup---------------------------
 stepper1.setMaxSpeed(600);//500
 stepper1.setAcceleration(200); //100
 stepper1.setCurrentPosition(4000); //required value for calibration


// ---------------- COMMS --------------------------------
    Serial.begin(9600);
    Serial.println("Time circuits activated!");

// ---------------- TFT -----------------------------------
    
    uint16_t ID = tft.readID();
    if (ID == 0xD3) ID = 0x9481;
    if (ID == 0xD3D3) ID = 0x9486;
    tft.begin(ID);
    tft.setRotation(1);
    tft.width();
    tft.height();

//--------------TEMP sensor setup---------------------------

  // Initialize the Temperature measurement library
  sensors.begin();

  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(SensCabin, 10);
  sensors.setResolution(SensIntake, 10);
  sensors.setResolution(SensCold, 10);
  sensors.setResolution(SensWarm, 10);

//------------------------ RELAY SETUP -----------------------

//RELAY SETUP
digitalWrite(OUT_RELAY_1, HIGH);
digitalWrite(OUT_RELAY_2, HIGH);
digitalWrite(OUT_RELAY_3, HIGH);
digitalWrite(OUT_RELAY_4, HIGH);
digitalWrite(OUT_RELAY_5, HIGH);
digitalWrite(OUT_RELAY_6, HIGH);
digitalWrite(OUT_RELAY_7, HIGH);
digitalWrite(OUT_RELAY_0, HIGH);
 
  pinMode(OUT_RELAY_1, OUTPUT);
  pinMode(OUT_RELAY_2, OUTPUT);
  pinMode(OUT_RELAY_3, OUTPUT);
  pinMode(OUT_RELAY_4, OUTPUT);
  pinMode(OUT_RELAY_5, OUTPUT);
  pinMode(OUT_RELAY_6, OUTPUT);
  pinMode(OUT_RELAY_7, OUTPUT);
  pinMode(OUT_RELAY_0, OUTPUT);

 //--------------------------- REST OF SETUP -----------------------------------
    
HomeScreenDraw();

//stepper calibration
stepper1.setCurrentPosition(4000);
stepper1.moveTo(0);
}

//---------------------------------- END OF SETUP -------------------------------------

//------------------------------ MAIN LOOP ---------------------------------------------

void loop()
{
  if (page == 0)
  {
  HomeScreenTouch();
  }


  if (page == 1)
  {
    FlapsScreenTouch();
  }

  if (page == 2)
  {
  StepperScreenTouch();
  }

if (abs(stepper1.distanceToGo()) > 0 )
  {
     stepper1.run();
  }

if (RUNstepper == 1){
  
  if((abs(stepper1.distanceToGo()) == 0 ) && (stepper1.currentPosition()== 0)){
  stepper1.moveTo(3800);
  }

  if((abs(stepper1.distanceToGo()) == 0 ) && (stepper1.currentPosition() == 3800)){
  stepper1.moveTo(0);
  }
  
  }
//Temperature read loop
TempReadOut();

}

second part as previous post was too long

//PODPROGRAMY

void HomeScreenDraw()
{
    tft.fillScreen(BLACK);
    tft.setTextColor(YELLOW);
    tft.setTextSize(2);
    tft.setCursor(10, 10);
    tft.println("REINSCH ENGINEERING - HVAC test v1");
    tft.setCursor(10,35);
    tft.println("Delorean DMC-12 vin#4454");
    FLAPS.initButton(&tft,  240, 90, 250, 60, YELLOW, YELLOW, BLACK, "FLAPS", 3);
    STEPPER.initButton(&tft, 240, 170, 250, 60, YELLOW, YELLOW, BLACK, "STEPPER", 3);
    FLAPS.drawButton(false);
    STEPPER.drawButton(false);
}
void HomeScreenTouch()
{    
   bool down = Touch_getXY();
    FLAPS.press(down && FLAPS.contains(pixel_x, pixel_y));
    STEPPER.press(down && STEPPER.contains(pixel_x, pixel_y));
   // if (FLAPS.justReleased())
   //     FLAPS.drawButton();
   // if (STEPPER.justReleased())
   //     STEPPER.drawButton();
    if (FLAPS.justPressed()) {
        FLAPS.drawButton(true);
        page=1;
        FlapsScreenDraw();
    }
    if (STEPPER.justPressed()) {
        STEPPER.drawButton(true);
        page=2;
        StepperScreenDraw();
    }

}

void FlapsScreenDraw()
{
  tft.fillScreen(BLACK);
  tft.setTextColor(YELLOW);
  tft.setTextSize(2);
  tft.setCursor(10, 10);
  tft.println("REINSCH ENGINEERING - HVAC test v1");
  tft.setCursor(10,35);
  tft.println("Press flap to activate.");
 
  FLAP1.initButton(&tft, 100, 140, 100, 70, YELLOW, RED, BLACK, "FLAP1", 2);
  FLAP2.initButton(&tft, 240, 140, 100, 70, YELLOW, RED, BLACK, "FLAP2", 2);
  FLAP3.initButton(&tft, 380, 140, 100, 70, YELLOW, RED, BLACK, "FLAP3", 2);
  FLAP4.initButton(&tft, 100, 230, 100, 70, YELLOW, RED, BLACK, "FLAP4", 2);
  FLAP5.initButton(&tft, 240, 230, 100, 70, YELLOW, RED, BLACK, "FLAP5", 2);
  MENU.initButton(&tft, 420, 270, 100, 70, YELLOW, YELLOW, BLACK, "MENU", 2);
  
  MENU.drawButton(false);
  
  Flap11();
  Flap22();
  Flap33();
  Flap44();
  Flap55();
  
}



void FlapsScreenTouch()
{
  bool down = Touch_getXY();

    FLAP1.press(down && FLAP1.contains(pixel_x, pixel_y));
    FLAP2.press(down && FLAP2.contains(pixel_x, pixel_y));
    FLAP3.press(down && FLAP3.contains(pixel_x, pixel_y));
    FLAP4.press(down && FLAP4.contains(pixel_x, pixel_y));
    FLAP5.press(down && FLAP5.contains(pixel_x, pixel_y));
    MENU.press(down && MENU.contains(pixel_x, pixel_y));

flapRUN(FLAP1, flap11,  OUT_RELAY_1, "flap1");
flapRUN(FLAP2, flap22,  OUT_RELAY_2, "flap2");
flapRUN(FLAP3, flap33,  OUT_RELAY_3, "flap3");
flapRUN(FLAP4, flap44,  OUT_RELAY_4, "flap4");
flapRUN(FLAP5, flap55,  OUT_RELAY_5, "flap5");


      if (MENU.justPressed())
      {
        MENU.drawButton(true);
        HomeScreenDraw();
        page=0;
      }
     
}

void StepperScreenDraw()
{
    tft.fillScreen(BLACK);
    tft.setTextColor(YELLOW);
    tft.setTextSize(2);
    tft.setCursor(10, 10);
    tft.println("Scroll button for position"); 
    tft.setCursor(30, 150);
    tft.print("Stepper position: ");
    tft.println(stepper1pozycja); 

    StepperScrollButton.initButton(&tft, 240, 100, 400, 30, RED, RED, RED, "", 2);
    StepperScrollButton.drawButton(false);
    tft.fillRoundRect((StepperScroll), 85, 30, 30, 5, MAGENTA);
    MENU.initButton(&tft, 420, 270, 100, 70, YELLOW, YELLOW, BLACK, "MENU", 2);
    MENU.drawButton(false);

    RUN.initButton(&tft, 420, 180, 100, 70, YELLOW, YELLOW, BLACK, "RUN", 2);

    if(RUNstepper==true)
  {
    RUN.drawButton(true);
  }
    else
      {
      RUN.drawButton(false); 
      }
}

void StepperScreenTouch()
{
   bool down = Touch_getXY();
    StepperScrollButton.press(down && StepperScrollButton.contains(pixel_x, pixel_y));
    MENU.press(down && MENU.contains(pixel_x, pixel_y));
    RUN.press(down && RUN.contains(pixel_x, pixel_y));
    
    if(StepperScrollButton.justPressed())
    {
    StepperScrollButton.drawButton(false);
    StepperScroll = pixel_x;
    stepper1pozycja = map(StepperScroll, 40, 440, 0, 4000);
    tft.fillRoundRect((StepperScroll), 85, 30, 30, 5, MAGENTA);
    tft.fillRect(30, 150, 300, 60, BLACK);
    tft.setTextColor(YELLOW);
    tft.setCursor(30, 150);
    tft.print("Stepper position: ");
    tft.println(stepper1pozycja); 
    stepper1.moveTo(stepper1pozycja);
    }
    if(MENU.justPressed())
    {
        MENU.drawButton(true);
        HomeScreenDraw();
        page=0;
    }
    
    if(RUN.justPressed())
    {
      if (RUNstepper == false){
        RUN.drawButton(true);
        RUNstepper = true;
        delay(50);
      }else {
        RUNstepper = false;
        RUN.drawButton(false);
        delay(50);
      }
      
    }



}

void VacuumOperation()
{
  tft.fillRoundRect(20, 130, 440, 100, 10, WHITE) ;
  tft.setCursor(75, 160);
  tft.setTextColor(RED);
  tft.setTextSize(2);
  tft.println("VACUUM ACTUATOR IN OPERATION");
  tft.setCursor(130, 190);
  tft.println("Please wait...");
}

void Flap11()
{
  if(flap11==false)
  {
    FLAP1.drawButton(true);
  }
    else
      {
      FLAP1.drawButton(false); 
      }
}

void Flap22()
{
  if(flap22==false)
  {
    FLAP2.drawButton(true);
  }
    else
      {
      FLAP2.drawButton(false);
      }
}

void Flap33()
{
  if(flap33==false)
  {
    FLAP3.drawButton(true);
  }
    else
      {
      FLAP3.drawButton(false);
      }
}

void Flap44()
{
  if(flap44==false)
  {
    FLAP4.drawButton(true);
  }
    else
      {
      FLAP4.drawButton(false);
      }
}

void Flap55()
{
  if(flap55==false)
  {
    FLAP5.drawButton(true);
  }
    else
      {
      FLAP5.drawButton(false);
      }
}

//---------------------------------------------------------

void TempReadOut()
{
  
  if(millis()-TempReadTime == 10000)
{
    sensors.requestTemperatures(); // Send the command to get temperature readings 

}

if(millis()-TempReadTime > 11000)
{
   // Serial.print("Temperature is: "); 
    //Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"? 
    TempReadTime=millis();

    tft.setTextColor(YELLOW);
    tft.setTextSize(2);

    tft.setCursor(10, 210);
    tft.print("Cabin:              'C");
    tft.fillRect(180,200,75,30, BLACK);
    tft.setCursor(185,210);
    tft.print(sensors.getTempC(SensCabin));

    tft.setCursor(10, 240);
    tft.print("Intake:             'C");
    tft.fillRect(180,230,75,30, BLACK);
    tft.setCursor(185,240);
    tft.print(sensors.getTempC(SensIntake));

    tft.setCursor(10, 270);
    tft.print("Evaporator:         'C");
    tft.fillRect(180,260,75,30, BLACK);
    tft.setCursor(185,270);
    tft.print(sensors.getTempC(SensCold));

    tft.setCursor(10, 300);
    tft.print("Heater:             'C");
    tft.fillRect(180,290,75,30, BLACK);
    tft.setCursor(185,300);
    tft.print(sensors.getTempC(SensWarm));
}
  
  }

//-------------------------------------------------------


void flapRUN ( Adafruit_GFX_Button FLAPN, boolean &flapNN,  byte RelayN, String flap_name)
{
    if (FLAPN.justPressed()) //FLAP1
    {   
        Serial.println(flapNN);  
        flapNN =! flapNN; //flap11
        Serial.println(flapNN);
        VacuumOperation();
        if(flapNN == true) //flap11
        {
            Serial.print("vacuum ");
            Serial.print(flap_name);
            Serial.println(" ON");
            digitalWrite(OUT_RELAY_0, LOW);
            delay(1500);
            digitalWrite(RelayN, LOW); //OUT_RELAY_1
            delay( 8000);
            digitalWrite(RelayN, HIGH);//OUT_RELAY_1
            delay(1500);
            digitalWrite(OUT_RELAY_0, HIGH);
            
        }
        else
        {
            Serial.print("vacuum");
            Serial.print(flap_name);
            Serial.println("OFF");
            digitalWrite(RelayN, LOW);//OUT_RELAY_1
            delay(5000);
            digitalWrite(RelayN, HIGH);//OUT_RELAY_1
            
        }
        
       FlapsScreenDraw(); 
    }
   
}

Effectively what you have done is this

int test = 123;

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  Serial.println(test);
  testFunction(456);
  Serial.println(test);
}

void loop()
{
}

void testFunction(int test)
{
  test++;
  Serial.println(test);
}

Run it and you will see that the global test variable is not updated in the function. That is because the test variable in the function is not the global one and this local one has its scope limited to the function and it is that one that is updated rather than the global one

Now try this version of the function

void testFunction(int wibble)
{
  test++;
  Serial.println(wibble);
}

Here the global test variable is updated in the function because there is not a local one