2015年6月28日日曜日

フルカラーLED制御

先ほどの準備に引き続き、LED制御の準備。
この方のようなものを作りたい。
http://blog.goo.ne.jp/jj1wkn/e/ddf87c5d2c5756c850e89c0fdfda50e1/?cid=87cbffdfe39692b52e94f842b9962d1e&st=0

ツールボックスを漁ると、眠っていたフルカラーLEDと抵抗(330Ω)が出てきた。
LEDの仕様が不明だったが、MSP430 LaunchpadでLチカにチャレンジ。
一応、以下のスケッチで ledPin(LaunchpadのP2_7ピン)から3.3Vの出力が出ることをテスターで確認したが、LEDは点灯できなかった。
P2_7ピンと赤色用アノードの間に上記抵抗を0~4パラまで試してみたが、全く反応なし。3.3Vでは電圧が低すぎる?

と思っていたら、まさかのアノードコモンの仕様でした。プラマイを逆にして無事点灯。
抵抗はよく分からんが、3パラ(110Ω)くらいでしょうか?
写真は4パラの状態。




■スケッチ「FullColorLED_150628」
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = PUSH2;     // the number of the pushbutton pin
const int ledPin =  P2_7;      // the number of the LED pin
const int ledPin2 =  GREEN_LED;      // the number of the LED pin

// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);    
  pinMode(ledPin2, OUTPUT);    
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT_PULLUP);  
}

void loop(){
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (digitalRead(buttonPin)==0) {  
    // turn LED on:  
    digitalWrite(ledPin, HIGH);
    digitalWrite(ledPin2, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
    digitalWrite(ledPin2, LOW);
  }
}

0 件のコメント:

コメントを投稿