#define borrow_gpio_in  21


pinMode(borrow_gpio_in, INPUT_PULLDOWN);


attachInterrupt(digitalPinToInterrupt(borrow_gpio_in), _lock_borrow, CHANGE );


void BookCase::_lock_borrow (){

noInterrupts();

return;

//通知服务器 锁状态变化
DynamicJsonDocument doc(256);

/*此处隐去部分逻辑代码*/

MQTT::pub_message(doc);

delayMicroseconds(100000);

interrupts ();
}


Generally, an ISR should be as short and fast as possible. If your sketch uses multiple ISRs, only one can run at a time, other interrupts will be executed after the current one finishes in an order that depends on the priority they have. millis() relies on interrupts to count, so it will never increment inside an ISR. Since delay() requires interrupts to work, it will not work if called inside an ISR. micros() works initially but will start behaving erratically after 1-2 ms. delayMicroseconds() does not use any counter, so it will work as normal.