Menyalakan Dan Mematikan LED Dengan Satu Tombol


Bahan:

- nodemcu/arduino

- LED

- push button


Skematik: 



Program:


int button = 2;

int nilaibutton;

int count;


int led = 13;


void setup() {

  Serial.begin(9600);

  pinMode(button, INPUT);

  pinMode(led, OUTPUT);

}


void loop() {

  nilaibutton = digitalRead(button);

  // Serial.println(nilaibutton);


  if (nilaibutton == 1) {

    count++;

    Serial.println(count);

    delay(300);

    if (count == 1) {

      digitalWrite(led, HIGH);

    }

    if (count == 2) {

      digitalWrite(led, LOW);

      count = 0;

    }

  }


}



إرسال تعليق

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.