PulseIn()

來(lái)自ALSROBOT WiKi
跳轉(zhuǎn)至: 導(dǎo)航搜索
unsigned long pulseIn (uint8_t pin, uint8_t state, unsigned long timeout) 			

讀脈沖

讀引腳的脈沖, 脈沖可以是 HIGH 或 LOW. 如果是 HIGH, 函數(shù)將先等引腳變?yōu)楦唠娖? 然后 開(kāi)始計(jì)時(shí), 一直到變?yōu)榈碗娖綖橹? 返回脈沖持續(xù)的時(shí)間長(zhǎng)短, 單位為毫秒. 如果超時(shí)還沒(méi)有 讀到的話(huà), 將返回0.

參數(shù):

  1. pin 引腳編號(hào)
  2. state 脈沖狀態(tài)
  3. timeout 超時(shí)時(shí)間

下面的例子演示了統(tǒng)計(jì)高電平的繼續(xù)時(shí)間:

int pin = 7;
unsigned long duration;

void setup()
{
  pinMode(pin, INPUT);
}

void loop()
{
  duration = pulseIn(pin, HIGH);
}