#define CAMERA_MODEL_XIAO_ESP32S3 // Define the camera model #include #include #include "camera_pins.h" // Declare the external function from app_httpd.cpp extern void startCameraServer(); const char* ssid = "Nkw"; const char* password = "plzwork123"; // Define the switch pin #define SWITCH_PIN 44 // GPIO 44 for the switch // Pointer for the latest captured image camera_fb_t* current_image = NULL; // Capture and overwrite the last image void capture_image() { Serial.println("Attempting to capture a new image..."); // Release the previous image if it exists if (current_image) { esp_camera_fb_return(current_image); current_image = NULL; // Avoid dangling pointer } // Capture a new image current_image = esp_camera_fb_get(); if (!current_image) { Serial.println("Failed to capture image"); return; } Serial.printf("New image captured, size: %d bytes\n", current_image->len); } void setup() { Serial.begin(115200); // Connect to Wi-Fi WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nWiFi connected"); Serial.println(WiFi.localIP()); // Camera configuration camera_config_t config = { .pin_pwdn = PWDN_GPIO_NUM, .pin_reset = RESET_GPIO_NUM, .pin_xclk = XCLK_GPIO_NUM, .pin_sccb_sda = SIOD_GPIO_NUM, .pin_sccb_scl = SIOC_GPIO_NUM, .pin_d7 = Y9_GPIO_NUM, .pin_d6 = Y8_GPIO_NUM, .pin_d5 = Y7_GPIO_NUM, .pin_d4 = Y6_GPIO_NUM, .pin_d3 = Y5_GPIO_NUM, .pin_d2 = Y4_GPIO_NUM, .pin_d1 = Y3_GPIO_NUM, .pin_d0 = Y2_GPIO_NUM, .pin_vsync = VSYNC_GPIO_NUM, .pin_href = HREF_GPIO_NUM, .pin_pclk = PCLK_GPIO_NUM, .xclk_freq_hz = 20000000, .ledc_timer = LEDC_TIMER_0, .ledc_channel = LEDC_CHANNEL_0, .pixel_format = PIXFORMAT_JPEG, .frame_size = FRAMESIZE_SVGA, .jpeg_quality = 10, .fb_count = 1 }; if (esp_camera_init(&config) != ESP_OK) { Serial.println("Camera init failed"); return; } //Reduce resolution to VGA (640x480) .frame_size = FRAMESIZE_VGA, //Reduce resolution to VGA (640x480) // Configure the switch pin pinMode(SWITCH_PIN, INPUT_PULLUP); // Use the external startCameraServer() function startCameraServer(); } void loop() { if (digitalRead(SWITCH_PIN) == LOW) { // LOW when pressed Serial.println("Switch pressed, capturing image..."); capture_image(); delay(500); // Debounce delay } }