const int buttonPin = 14; // Assuming the button is connected to pin 2
const int chipPin = 35;
bool buttonState = false;

void setup() {
    Serial.begin(115200);
    Serial.println("Hello, ESP32!");
    pinMode(buttonPin, INPUT_PULLUP); 
    pinMode(chipPin, OUTPUT);
}

void loop() {
    delay(1000);
    checkButton();
    anotherFunction1();
}

void myFunction(int &var) {
    var++; // Increment the counter
    Serial.print("Variable inside myFunction: ");
    Serial.println(var); 
    
    if (var >= 20) {
        var = 0; // Reset the counter to 0 if it reaches 20
    }
}

void anotherFunction1() {
    static int localVar = 0; // Declare localVar as a static variable
    myFunction(localVar); // Pass localVar by reference to myFunction
    Serial.print("Variable inside anotherFunction1: ");
    Serial.println(localVar); 
    
    if (buttonState) {
        localVar = 0; // Reset the counter to 0 if button is pressed
        Serial.println("Counter reset to 0");
        buttonState = false; // Reset button state
    }
}

void checkButton() {
    // Read the button state
    if (digitalRead(buttonPin) == LOW) {
        // Button is pressed
        buttonState = true;
        digitalWrite(chipPin, HIGH);
    }
}
my-chipBreakout