/*
Button
Turns on and off a light emitting diode(LED) connected to digital pin 11,
when pressing a pushbutton attached to pin 8.
The circuit:
- LED attached from pin 11 to ground through 220 ohm resistor
- pushbutton attached to pin 2 from +5V
- 10K resistor attached to pin 2 from ground
- Note: on most Arduinos there is already an LED on the board
attached to pin 11.
created 2022.4.27
by myunghak JOO
This example code is in the public domain.
8번핀을 버튼으로 사용하고 11번을 디지털 아웃핀으로 사용해서 릴레이나 LED를 연결하고
10ms 정도 ON 되었다고 5초정도 OFF를 연속으로 반복하는 동작
8번핀이 OFF(GND<->8번핀 결선)하면 동작하고 결선하지 않으면 동작하지 않음
https://www.arduino.cc/en/Tutorial/BuiltInExamples/Button
*/
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 8; // the number of the pushbutton pin
const int ledPin = 11; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == LOW) {
// turn LED on:
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(5000);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}