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?

Arduino UNO 3でカラーLED、Grove - Chainable RGB LEDで遊ぶ(P9813)

Last updated at Posted at 2024-09-15

参考

o_coq404.jpg

o_coq405.jpg

o_coq407.jpg

Grove Starter Kit for BeagleBone Green

結果

o_coq408.jpg

プログラム



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


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

  digitalWrite(19, LOW);//clk
  delay(20);                       // wait for a second
  digitalWrite(19, 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(18, LOW);//data
    } else {
      digitalWrite(18, 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(18, OUTPUT); //data
  pinMode(19, 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
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?