0
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をRGB.LEDスレーブI2Cして遊ぶ。

Last updated at Posted at 2024-10-18

目的
I2Cのテスト

結果

o_coq521.jpg

o_coq522.jpg

o_coq523.jpg

プログラム

受信 I2Cスレーブ M5NanoC6




//I2C_RGB_LED_V1_M5NanoC6_1


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


//ネオピクセルの定義
#define NUM_LEDS 1
Adafruit_NeoPixel strip(NUM_LEDS, M5NANO_C6_RGB_LED_DATA_PIN,
                        NEO_GRB + NEO_KHZ800);


//初期化
void setup() {

  // Enable RGB LED Power
  pinMode(M5NANO_C6_RGB_LED_PWR_PIN, OUTPUT);
  digitalWrite(M5NANO_C6_RGB_LED_PWR_PIN, HIGH);

  strip.begin();
  strip.show();


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

} //setup


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


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

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

  //                                 r  g  b
  strip.setPixelColor(0, strip.Color(r, g, b));
  strip.show();

} //receiveEvent


送信 I2Cマスター M5Stamp S3




//I2C_PUT_RGB_LED_M5S3_1


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


//初期化
void setup() {

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

} //setup


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

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

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

  //B 転送
  Wire.beginTransmission( (0x80)>>1 );
  Wire.write(0);
  Wire.write(0);
  Wire.write(255);
  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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?