Arduino Basics: LED ON/OFF with One Push Button | Example Code | English Subtitle

preview_player
Показать описание
Arduino Basics: LED ON/OFF with One Push Button | Example Code | English Subtitle
You can use a Relay to control High watt eqipements,
Code : code is on the comment below.
Please Subscribe my Channel. ThankYou!
Рекомендации по теме
Комментарии
Автор

const int ledPin = 13; // Pin connected to the LED
const int buttonPin = 2; // Pin connected to the button

// Variable to store the previous state of the button
int previousButtonState = HIGH;

void setup() {
// Initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
// Initialize the button pin as an input
pinMode(buttonPin, INPUT_PULLUP); // Enable internal pull-up resistor
}

void loop() {
// Read the current state of the button
int buttonState = digitalRead(buttonPin);

// Check if the button state has changed from HIGH to LOW
if (buttonState == LOW && previousButtonState == HIGH) {
// Toggle the LED state
digitalWrite(ledPin, !digitalRead(ledPin));
}

// Update the previous button state
previousButtonState = buttonState;
}

doit.
join shbcf.ru