micros()

名称

micros()

説明

Arduinoボードが現在のプログラムを起動してから経過した時間をマイクロ秒単位で返却する。この値は、約70分後にオーバーフロー(ゼロに戻る)する。Arduino Portentaファミリーからは、全てのコアで1マイクロ秒の精度がある。16MHzのArduinoボード(例えば、DuemilanoveやNano)では、この関数の精度は4 マイクロ秒である。すなわち、返却値はいつも4の倍数である)。8MHzのArduinoボード(例えば、LilyPad)では、この関数の精度は8マイクロ秒である。

書式

unsigned long micros();

引数

なし。

戻り値

Arduinoボードが現在のプログラムを開始してからのマイクロ秒。

使用例

以下のコードは、Arduinoボードが現在のプログラムを開始してからのマイクロ秒を返す。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
unsigned long time;

void setup() {
  Serial.begin(9600);
}
void loop() {
  Serial.print("Time: ");
  time = micros();

  Serial.println(time); //prints time since program started
  delay(1000);          // wait a second so as not to send massive amounts of data
}

注意

1ミリ秒は1000マイクロ秒で、1秒は1000000マイクロ秒である。

参照

オリジナルのページ

https://www.arduino.cc/reference/en/language/functions/time/micros/

Last Revision: 2021/02/24

実装の解析

micros()

最終更新日

January 4, 2024

inserted by FC2 system