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

More than 5 years have passed since last update.

GR-CitrusでフルカラーLEDをつけるよ

Last updated at Posted at 2019-03-31

GR-CitrusでフルカラーLEDを点けるよ

Lチカの時は、DigitalWriteを使いましたが、今回はAnarogWriteも使いますよ。
フルカラーLEDに抵抗を介してつなげます。
使用するピンは
A1 15 赤色
A2 16 緑色
A3 17 青色

使用するLEDによって、LEDを制御するピンが異なります。
今回は、秋月電子のフルカラーLEDと同じものを使用しました。
なお、抵抗は本来は100Ω程度でいいようです。
http://akizukidenshi.com/catalog/g/gI-02476/

GR-Citrus-WIre-Fullcolor.jpg

/* GR-CITRUS Sketch Template V2.20 */
# include <Arduino.h>

void setup(){
    Serial.begin(9600);
    pinMode(PIN_LED0, OUTPUT);
    pinMode(15, OUTPUT);     //Pin15を出力にするよ(赤)
    pinMode(16, OUTPUT);     //Pin16を出力にするよ(緑)
    pinMode(17, OUTPUT);     //Pin17を出力にするよ(青)
}

void loop(){
    Serial.println("LED Test");
 // 赤色
  analogWrite(15,255);
  analogWrite(16,  0);
  analogWrite(17,  0);
  delay(1000);
  
  // 緑色
  analogWrite(15,  0);
  analogWrite(16,255);
  analogWrite(17,  0);
  delay(1000);
 
  // 青色
  analogWrite(15,  0);
  analogWrite(16,  0);
  analogWrite(17,255);
  delay(1000);  
  
   // 赤色+緑色
  analogWrite(15,255);
  analogWrite(16,255);
  analogWrite(17,  0);
  delay(1000);
  
  // 緑色+青色
  analogWrite(15,  0);
  analogWrite(16,255);
  analogWrite(17,255);
  delay(1000);
 
  // 赤色+青色
  analogWrite(15,255);
  analogWrite(16,  0);
  analogWrite(17,255);
  delay(1000);  
  
    // 赤色+緑色+青色
  analogWrite(15,255);
  analogWrite(16,255);
  analogWrite(17,255);
  delay(1000);  
}

次は、各色の色を混じらせてみました。

/* GR-CITRUS Sketch Template V2.20 */
# include <Arduino.h>

void setup(){
    Serial.begin(9600);
    pinMode(PIN_LED0, OUTPUT);
    pinMode(15, OUTPUT);     //Pin15を出力にするよ
    pinMode(16, OUTPUT);     //Pin16を出力にするよ
    pinMode(17, OUTPUT);     //Pin17を出力にするよ
}

void loop(){
    Serial.println("LED");
   for(int i = 0; i < 256; i++){
        analogWrite(15, i);
        analogWrite(16,	0);
        analogWrite(17,	0);
        delay(10);
    }    
   for(int i = 0; i < 256; i++){
        analogWrite(15, 0);
        analogWrite(16,	i);
        analogWrite(17,	0);
        delay(10);
    } 
   for(int i = 0; i < 256; i++){
        analogWrite(15, 0);
        analogWrite(16,	0);
        analogWrite(17,	i);
        delay(10);
    }   
       for(int i = 0; i < 256; i++){
        analogWrite(15, i);
        analogWrite(16,255);
        analogWrite(17,  0);
        delay(10);
    }
       for(int i = 0; i < 256; i++){
        analogWrite(15, i);
        analogWrite(16,0);
        analogWrite(17,255);
        delay(10);
    }
		for(int i = 0; i < 256; i++){
        analogWrite(15, 255);
        analogWrite(16,	i);
        analogWrite(17,	0);
        delay(10);
    } 
		for(int i = 0; i < 256; i++){
        analogWrite(15, 255);
        analogWrite(16,	0);
        analogWrite(17,	i);
        delay(10);
    } 
		for(int i = 0; i < 256; i++){
        analogWrite(15, 0);
        analogWrite(16,	i);
        analogWrite(17,	255);
        delay(10);
    }   
		for(int i = 0; i < 256; i++){
        analogWrite(15, 0);
        analogWrite(16,	255);
        analogWrite(17,	i);
        delay(10);
    } 
        for(int i = 0; i < 256; i++){
        analogWrite(15, 255);
        analogWrite(16,	i);
        analogWrite(17,	255);
        delay(10);
    } 
		for(int i = 0; i < 256; i++){
        analogWrite(15, 255);
        analogWrite(16,	255);
        analogWrite(17,	i);
        delay(10);
    }   
}
0
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
0
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?