LoginSignup
0
0

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

Last updated at Posted at 2024-04-18

目的
I2Cのテスト

o_coq044.jpg

受信 I2Cスレーブ StampS3



//I2C_1GPIO_V1_M5S3_1


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


//初期化
void setup() {

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

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

} //setup


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


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

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

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

    neopixelWrite(21,0,0,0);

  } else {

    neopixelWrite(21,64,0,0);

  } //endif

} //receiveEvent

送信 I2Cマスター Arduino UNO




//I2C_PUT_0_1_UNO_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



0
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
0
0