int ledPin = 13; // LED 연결 디지털 핀 13
void setup() {
pinMode(ledPin, OUTPUT); // 디지털 핀을 출력으로
}
void loop() {
digitalWrite(ledPin, HIGH); // LED 켬
delay(1000); // 1초 기다림
digitalWrite(ledPin, LOW); // LED 끔
delay(1000); // 1초 기다림
}
주의와 경고
delay() 함수로 깜빡이는 LED 를 만들기 쉽고, 많은 스케치가 짧은 delay를 써서 그런 작업을 switch debouncing로 하지만, 스케치에서 delay() 를 쓰는 것은 눈에 띄는 단점이 있다.
delay 함수 동안 센서 읽기, 수학 계산, 핀 다루기가 중단되므로, 결과적으로, 거의 모든 다른 작업이 멈춘다.
시간을 제어하는 다른 접근으로 아래에 있는 millis() 함수와 스케치를 보세요.
좀더 똑똑한 프로그래머는 delay() 를 10 밀리초보다 긴 타이밍 이벤트를 아두이노 스케치가 아주 간단한 경우가 아니면 대개 사용하지 않는다.
그러나, 어떤 것은 delay() 함수가 Atmega 칩을 제어하는 동안에도 이루어지는데, 왜냐면 delay 함수가 인터럽트를 비활성화 하지 않기 때문이다.
RX에서 나타나는 시리얼 통신은 기록되고, PWM (analogWrite) 값과 핀 상태가 유지되며, interrupts 은 정상으로 동작한다.
We care about the privacy and personal data of our users.
To continue, please give us your consent:
Please confirm that you have read the privacy policy
Thank you for subscribing!
Curious to learn more?
Are you also a teacher, student, or professional that loves using Arduino in your day-to-day activities?
Then keep up-to-date with either our STEM or Professional monthly newsletters.
Arduino weekly newsletter (already subscribed)
Educators can benefit from the ever growing tech that shapes our environment through fun cool projects.
Why not awe your boss with highly innovative ways to help keep your enterprise connected at no extra cost?
Arduino Survey
We'd like to get to know you little better.
Please help us improve by answering this super short optional survey.