1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

M5NanoC6を1LEDスレーブI2Cして遊ぶ。

Last updated at Posted at 2024-10-16

目的
I2Cのテスト

結果

o_coq518.jpg

プログラム

受信 I2Cスレーブ M5NanoC6




//I2C_1GPIO_V1_M5NanoC6_1


//インクルド
#include <Arduino.h>
#include <Wire.h>
#include <M5NanoC6.h>


//初期化
void setup() {

  //i2cの初期化
  Wire.begin( (0x80)>>1 );      //I2Cスレーブアドレスの設定
  Wire.onReceive(receiveEvent); //データが来ると呼ばれる関数

  //GPIOの初期化
  pinMode(M5NANO_C6_BLUE_LED_PIN, OUTPUT);

} //setup


//メインループ
void loop() {
  delay(1); //ダミー
} //loop


//レシーブイベント
void receiveEvent(int howMany) {

  int x = Wire.read(); //I2C受信データの読み込み

  //LEDの点滅
  if( (x & 0x01) == 0 ) {

    digitalWrite(M5NANO_C6_BLUE_LED_PIN, LOW);//点灯
    
  } else {

    digitalWrite(M5NANO_C6_BLUE_LED_PIN, HIGH);//消灯

  } //endif

} //receiveEvent


送信 I2Cマスター M5Stamp S3



//I2C_PUT_0_1_M5S3_1


//インクルド
#include <Arduino.h>
#include <Wire.h>


//初期化
void setup() {

  Wire.begin();    //I2Cの初期化

} //setup


//メインループ
void loop() {

  //'0'転送
  Wire.beginTransmission( (0x80)>>1 );
  Wire.write('0');
  Wire.endTransmission();
  delay(1000); //1秒待つ

  //'1'転送
  Wire.beginTransmission( (0x80)>>1 );
  Wire.write('1');
  Wire.endTransmission();
  delay(1000); //1秒待つ

} //loop


1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?