const int led = 16 ;
const int pir = 19 ;
bool motionDetected = false;
void IRAM_ATTR detectsMovement(){
Serial.println("movimiento detectado");
digitalWrite(led, HIGH);
motionDetected = true;
}
void setup() { //deir las entradas y salidas a utilizar
// put your setup code here, to run once:
pinMode(led, OUTPUT);
pinMode(pir, INPUT);
attachInterrupt(digitalPinToInterrupt(pir), detectsMovement , RISING );
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(motionDetected)
{
motionDetected= false;
delay(2000);
digitalWrite(led, LOW);
}
delay(1000);
}