0Pricing
Arduino & IoT Academy · Ders

if/else: LED Düğmeyi İzler

LED'i yalnızca düğme basılı tutulduğu sürece yakın.

if/else: LED Düğmeyi İzler, CoddyKit'te ücretsiz bir Arduino & IoT Academy dersidir. Bu, 4 dersinin 3. 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.

Make a Decision

Reading a button is great, but the magic is reacting to it. An if statement lets your board choose what to do based on the reading.

if Runs Conditionally

The code inside if only runs when its test is true. So you can light an LED only when the button is actually pressed.

if (state == LOW) {
  // button is pressed
}

Test for Pressed

Remember the inversion: with INPUT_PULLUP, pressed is LOW. So your condition checks whether the stored state equals LOW.

int state = digitalRead(2);
if (state == LOW) {
  digitalWrite(13, HIGH);
}

Add an else Branch

What about when it isn't pressed? The else block runs whenever the if test is false, giving you the other half of the behavior.

if (state == LOW) {
  digitalWrite(13, HIGH);
} else {
  digitalWrite(13, LOW);
}

LED Follows the Button

Together if and else make the LED mirror the button: on while held, off when released. That is your first real input-to-output link. 💡

Set Up Both Pins

The button pin is an input and the LED pin is an output. Declare both modes in setup() so each pin knows its job.

void setup() {
  pinMode(2, INPUT_PULLUP);
  pinMode(13, OUTPUT);
}

One Equals vs Two

A classic trap: use == to compare, not a single =. One equals assigns a value, while two equals asks if they match.

Loop Keeps It Live

Put the whole thing in loop() so it checks the button thousands of times a second. The LED reacts the moment you press.

Read Then Decide

The pattern is always the same: read the input, then decide with if/else. Get comfortable with it; you'll reuse it everywhere.

Compare Right in the if

You can skip the variable and test the read directly. It reads cleanly and does exactly the same comparison inside the parentheses.

if (digitalRead(2) == LOW) {
  digitalWrite(13, HIGH);
}

From Sensing to Acting

You just closed the loop from input to output with pure logic. Swap the LED for a buzzer or motor and the same idea still drives it.

Quick Check

Pick the condition that lights the LED while the button is held.

Recap

You used if/else to make an LED follow a button: LOW lights it, HIGH turns it off. Remember == for comparison. Next you'll wire it all up. 🔌

Sıkça Sorulan Sorular

“if/else: LED Düğmeyi İzler” dersi ücretsiz mi?

Evet — “if/else: LED Düğmeyi İzler” 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.

“if/else: LED Düğmeyi İzler” dersinde ne öğreneceğim?

LED'i yalnızca düğme basılı tutulduğu sürece yakı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 3. dersidir.

“if/else: LED Düğmeyi İzler” 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. INPUT ve INPUT_PULLUP
  2. Bir Düğmenin Durumunu Okuma
  3. if/else: LED Düğmeyi İzler
  4. Bir Breadboard'a Düğme Bağlama
← Arduino & IoT Academy Sayfasına Dön