//I2C_Slave_8byte_test1_UNO3_2
//インクルド
#include <Arduino.h>
#include <Wire.h> // I2C
//定義
volatile unsigned char buf[32+1] = {
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0};
//初期化
void setup() {
//シリアルポートの初期化
Serial.begin(9600);
//I2Cの初期化
Wire.begin( 0x1e ); // I2Cスレーブアドレスの設定
Wire.onReceive(receiveEvent); // データが来ると呼ばれる関数
} //setup
//メインループ
void loop() {
if (buf[0] != 0) { //空文では、ない場合
delay(20); //[必要]ちょっと待つ(消すな)
//受信データの出力
Serial.print((char *)(&buf));
Serial.println();
buf[0] = 0; //空文
} //endif
delay(3); //ダミー
} //loop
//レシーブイベント(受信)
void receiveEvent(int howMany) {
int i = 0;
while (0 < Wire.available() && (i < 32) ) { // loop through all but the last
// I2C受信データの読み込み
buf[i++] = Wire.read(); // receive byte as a character
} //while
} //receiveEvent