delayMicroseconds()
매개변수에 지정된 시간(마이크로 초)동안 프로그램을 멈춘다. 1밀리초는 1000 마이크로 초, 1초는 100만 마이크로 초. 현재, 정확한 delay를 만드는 가장 큰 값은 16383. 미래의 아두이노 릴리스에서 바뀔 수 있다. delay 가 몇 천 마이크로 초 보다 길면, 대신 delay() 를 써야 한다.
이 코드는 핀번호 8이 출력 핀으로 동작하도록 구성한다. 약 100 마이크로 초의 펄스 열을 보낸다. 근사값은 코드에서 다른 명령 실행으로 인한 것이다.
int outPin = 8;
void setup() {
pinMode(outPin, OUTPUT);
}
void loop() {
digitalWrite(outPin, HIGH);
delayMicroseconds(50);
digitalWrite(outPin, LOW);
delayMicroseconds(50);
}
Generate a 10-microsecond pulse for use in ultrasonic sensor
int trigPin = 9;
int echoPin = 8;
float duration_us, distance_cm;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration_us = pulseIn(echoPin, HIGH);
distance_cm = 0.017 * duration_us;
Serial.print("distance: ");
Serial.print(distance_cm);
Serial.println(" cm");
delay(500);
}
※ 주의 및 경고:
이 함수는 3 마이크로 초 이상 범위에서 매우 정확하게 돌아간다. delayMicroseconds 가 작은 지연시간동안 정확히 수행한다고 보장할 수 없다. 아두이노 0018 현재, delayMicroseconds() 는 더이상 인터럽트를 비활성화 하지 않는다.
※ ARDUINO BUY RECOMMENDATION
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.
※ OUR MESSAGES
Any suggestion, correction, and translation? please email us at ArduinoGetStarted@gmail.com, We appreciate it
We mainly keep improving the references in English. See
English version of this page for the latest update.
Follow Us