Loading
Loading
IoT Lab content is currently available in Arabic only. We're working on an English version.
عرض بالعربية →How to detect a button press instantly even if Arduino is busy doing something else.
Connect the button to pin 2 or 3.
volatile bool state = false;
void setup() {
pinMode(13, OUTPUT);
pinMode(2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), blink, FALLING);
}
void loop() {
// الأردوينو نائم في دالة delay لا نهاية لها، لكن المقاطعة ستعمل
delay(10000);
}
void blink() {
state = !state;
digitalWrite(13, state);
}Writing a long ISR function or one containing delay() or Serial.print(). The ISR must be lightning-fast (change a variable and exit).