មេរៀនទី ៣: Button Input ដើម្បីគ្រប់គ្រង

Fire LED Lesson (2D)

មេរៀនទី ៣: Button Input ដើម្បីគ្រប់គ្រង

*********************************************************************************************************************

🎯 គោលបំណងមេរៀន

ស្គាល់ការប្រើ Push Button ជា Input
• គ្រប់គ្រង LED ដោយប្រើ Button
• យល់អំពី INPUT_PULLUP
🔌 របៀបភ្ជាប់ឧបករណ៍

• Button Pin 1 → Arduino Pin 2
• Button Pin 2 → GND
• LED (+) → Arduino Pin 13
• LED (–) → Resistor 220Ω → GND
💻 Arduino Code

// Lesson 3: Button Input Control

int buttonPin = 2;
int ledPin = 13;

void setup() {
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  int buttonState = digitalRead(buttonPin);

  if (buttonState == LOW) {
    digitalWrite(ledPin, HIGH);
  } else {
    digitalWrite(ledPin, LOW);
  }
}

Post a Comment

0 Comments