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?

[I2C]M5StampS3、1ビット拡張エキスパンダー(I2Cスレーブ拡張I.O)

Last updated at Posted at 2025-08-12
  • 3.3.0

参考

結果

IMG_5111.jpeg

IMG_5110.jpeg

Screenshot from 2025-08-13 06-49-30.png

プログラム



//I2C_Slave_1bit_ext_out_Stamp_S3_1


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


//初期化
void setup() {

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

  //GPIOの初期化
  pinMode(21, OUTPUT);  // sets the LED pin as output

}  //setup


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

  delay(3);  // ダミー

}  //loop


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

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

  x = x & 0x01;  // 最下位の1ビットをマスクして取り出す

  // 1bit出力
  if (x == 0) {
    neopixelWrite(21, 64, 0, 0);
  } else {
    neopixelWrite(21, 64, 64, 64);
  }  //endif

}  //receiveEvent



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?