0Pricing
Arduino & IoT Academy · Ders

Bir Uçta attachInterrupt

Bir sinyal değiştiği anda kod çalıştırın.

Bir Uçta attachInterrupt, CoddyKit'te ücretsiz bir Arduino & IoT Academy dersidir. Bu, 4 dersinin 2. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Arduino & IoT Academy öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Arduino & IoT Academy kursu toplamda 4 dersten oluşur.

Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.

Wiring Code to a Pin

The attachInterrupt function tells your board: watch this pin, and the moment its signal changes, run my function right away.

Only Special Pins

Not every pin supports interrupts. On an Uno only pins 2 and 3 do, so plug your signal into one of those.

Translate Pin to Number

Wrap the pin in digitalPinToInterrupt so the right interrupt number is used. It keeps your code portable across boards.

digitalPinToInterrupt(2);

Three Pieces

You give attachInterrupt three things: which pin to watch, the function to run, and the kind of change that should trigger it.

attachInterrupt(digitalPinToInterrupt(2), myISR, RISING);

The Handler Function

The function you name is your handler, also called an ISR. The board calls it automatically; you never call it yourself.

void myISR() {
  flag = true;
}

RISING Edge

Pass RISING to fire when the pin goes from LOW to HIGH, like the moment a signal first switches on. 📈

FALLING Edge

Pass FALLING to fire when the pin drops from HIGH to LOW. A pull-up button often triggers here, since pressing pulls the pin down.

CHANGE Mode

Pass CHANGE to fire on either edge, both up and down. It is handy when you care about every transition of the signal.

Set It Up in setup()

Call attachInterrupt once inside setup, right after you set the pin mode. From then on the watching happens on its own.

pinMode(2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), myISR, FALLING);

The Loop Stays Light

With the interrupt attached, your loop no longer polls that pin. The handler runs only when the chosen edge actually occurs.

Turning It Off

If you ever need to stop watching, detachInterrupt removes the link. Most projects attach once and never detach.

detachInterrupt(digitalPinToInterrupt(2));

Quick Check

Which trigger mode fires only when a pin goes from LOW up to HIGH?

Recap

You learned to call attachInterrupt with a pin, a handler, and a mode like RISING. Now hardware runs your code the instant a signal changes. 🎉

Sıkça Sorulan Sorular

“Bir Uçta attachInterrupt” dersi ücretsiz mi?

Evet — “Bir Uçta attachInterrupt” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Arduino & IoT Academy kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Arduino & IoT Academy kursu toplamda 4 dersten oluşur.

“Bir Uçta attachInterrupt” dersinde ne öğreneceğim?

Bir sinyal değiştiği anda kod çalıştırın. Arduino & IoT Academy ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.

Arduino & IoT Academy öğrenmeye başlamak için deneyim gerekli mi?

Önceden deneyim gerekmez. CoddyKit'te Arduino & IoT Academy, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 2. dersidir.

“Bir Uçta attachInterrupt” dersi ne kadar sürer?

Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.

Bu Arduino & IoT Academy dersinde kod yazıp çalıştırabilir miyim?

Evet. Her Arduino & IoT Academy dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.

Bu kursun tüm dersleri

  1. Yoklama ve Kesintiler
  2. Bir Uçta attachInterrupt
  3. Güvenli Bir ISR Yazın
  4. Kodlayıcıdan Gelen Darbeleri Sayın
← Arduino & IoT Academy Sayfasına Dön