#include <Servo.h>  // Include the Servo library
#define servo_pin 9         // Define the pin for the servo
int capacitive_sensor = 2;  // Define the pin for the capacitive sensor
int magnetic_sensor = 3;    // Define the pin for the magnetic sensor
int close_pos = 0;
int open_pos = 180;
Servo myServo;  // Create a servo object
void setup() {
  Serial.begin(9600);                        // Initialize serial communication
  myServo.attach(servo_pin);                 // Attach the servo to the specified pin
  pinMode(capacitive_sensor, INPUT_PULLUP);  // Set the capacitive sensor pin as input with pull-up resistor
  pinMode(magnetic_sensor, INPUT_PULLUP);    // Set the magnetic sensor pin as input with pull-up resistor
  myServo.write(close_pos);
}
void loop() {
  int cap = digitalRead(capacitive_sensor);  // Read the state of the capacitive sensor
  int mag = digitalRead(magnetic_sensor);    // Read the state of the magnetic sensor
  if (cap && mag) {                      // If both sensors are not triggered
    Serial.println("----------------------------------servo run");
    myServo.write(close_pos);  // Move the servo to 90 degrees
    delay(3000);        // Wait for 1 second
    myServo.write(open_pos);   // Move the servo to 0 degrees
  } else {              // If either sensor is triggered
    myServo.write(open_pos);   // Move the servo to 0 degrees
  }
  Serial.print("cap :");
  Serial.println(cap);
  Serial.print("mag :");
  Serial.println(mag);
}
FPS: 0
Power: 0.00W
Power: 0.00W