attachInterrupt()

Used Products:

1. 10 KΩ
2. Arduino UNO

Content:

Çeşme: https://www.arduino.cc/en/Reference/AttachInterrupt

Code:

#define BLINK_LED_PIN 13 #define INTERRUPT_LED_PIN 8 #define BUTTON_PIN 2 long start = 0; void setup() { Serial.begin(9600); pinMode(INTERRUPT_LED_PIN, OUTPUT); pinMode(BLINK_LED_PIN, OUTPUT); pinMode(BUTTON_PIN, INPUT); digitalWrite(BUTTON_PIN, HIGH); randomSeed(millis()); delay(random(1000,3000)); digitalWrite(INTERRUPT_LED_PIN, 0); digitalWrite(BLINK_LED_PIN, HIGH); attachInterrupt(0,react,FALLING); start = millis(); } void loop() { digitalWrite(BLINK_LED_PIN, 1); delay(5000); digitalWrite(BLINK_LED_PIN, 0); delay(5000); } void react() { long fin = millis(); Serial.print("Your reaction time: "); Serial.println(fin-start); digitalWrite(INTERRUPT_LED_PIN, !digitalRead(INTERRUPT_LED_PIN)); }