onRequest()

Last revision:2026/01/24

名称

Wire.onRequest()

説明

onRequest()は、コントローラーデバイスが周辺機器からのデータを要求したときに呼び出される関数を登録する。

この関数はWireライブラリの一部である。詳細はWireメインページを参照のこと。

書式

Wire.onRequest(handler)

C言語シグネチャ(avr)

void TwoWire::onRequest( void (*function)(void) );

引数

handlerデータ要求時に呼び出されるコールバック関数。以下のシグネチャを持つ必要がある。
パラメータ: なし。
戻り値: void(なし)

戻り値

なし。

コード例

1
2
3
4
5
6
7
8
void setup() {
  Wire.begin(0x08);             // Join I2C bus as peripheral with address 0x08
  Wire.onRequest(requestEvent); // Register callback function
}

void requestEvent() {
  Wire.write("Hello");  // Send data to controller
}

オリジナルのページ

https://docs.arduino.cc/language-reference/en/functions/communication/wire/onRequest/

最終更新日

August 16, 2026

inserted by FC2 system