Need help for esp32-cam code

Hardware model + communication type: esp32-cam with wifi
Smartphone OS (iOS or Android) + version: Android 11
Blynk server, Blynk Library version: 0.6.1

I simplified the code which is uploaded. It detects motion and flame and then alarms and sends a photo to Blynk app. It worked but I want to make a button and timer for on and off.
I need help for the code to make the Function() is off when the BUTTON or TIMER is off.
I made button widget to GPIO15, Timer widget to GPIO2.
The code copiles but I don’t know how to shut on and off with the button and timer.
any comment would be helpful. thanks.


#define FLAME 12
#define PIR 13
#define LED 4
#define BUTTON 15
#define TIMER 2


void loop() {
  Blynk.run();
  Function();
}

void Function(){
if(digitalRead(FLAME) == LOW ){
  Serial.println("Send Notification");
  Blynk.notify("Fire Detected...");
  Serial.println("Capture Photo");
  takePhoto();
  String path = "/picture" + String(pictureNumber) +".jpg";  
  Serial.printf("Picture file name: %s\n", path.c_str());
  takeSavePhoto(path);
  pictureNumber++;
  delay(3000);
  }
  
  if(digitalRead(PIR) == LOW){
  Serial.println("Send Notification");
  Blynk.notify("Intruder Detected...");
  Serial.println("Capture Photo");
  takePhoto();
  String path = "/picture" + String(pictureNumber) +".jpg";  
  Serial.printf("Picture file name: %s\n", path.c_str());
  takeSavePhoto(path);
  pictureNumber++;
  delay(3000);
  }
  
  if(digitalRead(PHOTO) == HIGH){
  Serial.println("Capture Photo");
  takePhoto();
  String path = "/picture" + String(pictureNumber) +".jpg";  
  Serial.printf("Picture file name: %s\n", path.c_str());
  takeSavePhoto(path);
  pictureNumber++;
  }
}

A post was merged into an existing topic: Flame sensor with esp32 cam