#include <STM32LowPower.h>

const int pirPin = A0; // Chân kết nối cảm biến PIR
const int ledPin = D13; // Chân kết nối đèn LED onboard
volatile bool motionDetected = false;

void setup() {
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);

  // Thiết lập ngắt để theo dõi cảm biến PIR
  attachInterrupt(digitalPinToInterrupt(pirPin), motionInterrupt, CHANGE);
}

void loop() {
  // 
}

void motionInterrupt() {
  Serial.println("Button pressed!");

  // Turn on the LED for 2 seconds
  digitalWrite(ledPin, HIGH);
  delay(2000);
  digitalWrite(ledPin, LOW);

  // Chuyển vào chế độ ngủ để tiết kiệm năng lượng
  LowPower.sleep();
}
nucleo:D1
nucleo:D0
nucleo:RST.1
nucleo:GND.1
nucleo:D2
nucleo:D3
nucleo:D4
nucleo:D5
nucleo:D6
nucleo:D7
nucleo:D8
nucleo:D9
nucleo:D10
nucleo:D11
nucleo:D12
nucleo:VIN
nucleo:GND.2
nucleo:RST.2
nucleo:5V
nucleo:A7
nucleo:A6
nucleo:A5
nucleo:A4
nucleo:A3
nucleo:A2
nucleo:A1
nucleo:A0
nucleo:REF
nucleo:3V3
nucleo:D13
led1:A
led1:C
btn1:1.l
btn1:2.l
btn1:1.r
btn1:2.r
r1:1
r1:2