1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

XIAO ESP32C6でカラーLED、Grove - Chainable RGB LEDで遊ぶ(P9813)

Last updated at Posted at 2025-04-11

いろいろ、注意

  • 過去ログを見てね、おねがいします。
  • まぶしい
  • 3.2.0

結果

image_original (83).jpg

image_original (84).jpg

image_original (85).jpg

プログラム



//Chainable_LED_XIAO_ESP32C6_1
//1個専用のカラーRGB LEDのライブラリ


//送信クロックの発生
void clk() {

  digitalWrite(D9, LOW);//clk
  delay(20);                       // wait for a second
  digitalWrite(D9, HIGH);//clk
  delay(20);                       // wait for a second

}//clk


//1バイトを送信する
void sendByte(int b) {

  for (int i = 0; i < 8; i++) {
    if ( (b & 0x80) == 0) {
      digitalWrite(D10, LOW);//data
    } else {
      digitalWrite(D10, HIGH);//data
    }//endif
    clk();
    b = b << 1;
  }//for i

}//sendByte


//1個のLED専用
void setColorRGB(int red, int green, int blue) {

  //開始
  sendByte(0);
  sendByte(0);
  sendByte(0);
  sendByte(0);

  //ここから
  int prefix = 0b11000000;
  if( (blue  & 0x80)==0 ) {prefix = prefix | 0b00100000;}
  if( (blue  & 0x40)==0 ) {prefix = prefix | 0b00010000;}

  if( (green & 0x80)==0 ) {prefix = prefix | 0b00001000;}
  if( (green & 0x40)==0 ) {prefix = prefix | 0b00000100;}

  if( (red   & 0x80)==0 ) {prefix = prefix | 0b00000010;}
  if( (red   & 0x40)==0 ) {prefix = prefix | 0b00000001;}
  sendByte(prefix);

  sendByte(blue);
  sendByte(green);
  sendByte(red);
  //ここまで

  //終了
  sendByte(0);
  sendByte(0);
  sendByte(0);
  sendByte(0);

}//setColorRGB


// the setup function runs once when you press reset or power the board
void setup() {
  //GPIOポートの初期化
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(D10, OUTPUT); //data
  pinMode(D9, OUTPUT); //clk
}//setup


// the loop function runs over and over again forever
void loop() {

  //赤
  setColorRGB(0x55, 0x00, 0x00);
  delay(500);                       // wait for a second

  //緑
  setColorRGB(0x00, 0x55, 0x00);
  delay(500);                       // wait for a second

  //青
  setColorRGB(0x00, 0x00, 0x55);
  delay(500);                       // wait for a second
  
}//loop



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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?