フルカラーLEDで小手調べ
犬小屋IT化やら将来子供に教えるやらで始めた電子工作ですが、ネットを色々見ているとそれ以外の事もやってみたくなってみたり。SparkFunのBlueSMIRFモジュール(Bluetooth)とBlackBerryで二足歩行ロボットの制御を(無駄に)やってみたくなったり。。。
と、色々と夢は膨らみますが、とりあえずは基本から。というわけで、中学生の頃からずっと敬愛してやまないスタパ斉藤氏が提言する、「Lチカ」なるものをやってみました。(Lチカ=LEDチカチカ) モノは、単色ではいまいち面白味に欠けるので、秋月で買ってきたフルカラーLEDです。各色の順方向電流が、20mAで、電圧VFが赤2.0V、緑青3.6Vなので、Aurduinoの各端子から供給される電圧5Vから抵抗を計算すると以下の通りとなります。
- 赤 (5.0 – 2.0) / 0.020 = 150Ω
- 青緑 (5.0 – 3.6) / 0.020 = 70Ω
手持ちの抵抗でぴったりのものはないので、100Ωを何個か使った合成抵抗でいきます。100Ω2個平行に繋ぐと50Ωになるという、あれです。4個で25Ωになります。70Ωは75Ωくらいにでも大丈夫だろうと勝手に想像し、50+25でいきます。そして、できあがったブレッドボードは以下の様な感じです。カソードコモンなので、カソード1本をマイナスに繋ぎ、残りの赤青緑は抵抗を介してそれぞれArduinoの9番、10番、11番に繋ぎます。(何故このピンなのかは後日。PWMってやつです。)
とりあえず最初はサンプルスケッチのBlinkを応用して各色順番に1秒毎に点滅させます。
/* Full Color Blink Turns on a color for one second, then off for one second, and change color repeatedly. The circuit: * LED connected from digital pin 9, 10, 11 to ground. Created 3rd March 2010 By Hiroshi Takahashi http://blog.on-rails.com */ int redLedPin = 11; // Red LED connected to digital pin 11 int blueLedPin = 10; // Blue LED connected to digital pin 10 int greenLedPin = 9; // Green LED connected to digital pin 9 // The setup() method runs once, when the sketch starts void setup() { // initialize the digital pin as an output: pinMode(redLedPin, OUTPUT); pinMode(blueLedPin, OUTPUT); pinMode(greenLedPin, OUTPUT); } // the loop() method runs over and over again, // as long as the Arduino has power void loop() { digitalWrite(redLedPin, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(redLedPin, LOW); // set the LED off delay(1000); // wait for a second digitalWrite(blueLedPin, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(blueLedPin, LOW); // set the LED off delay(1000); // wait for a second digitalWrite(greenLedPin, HIGH); // set the LED on delay(1000); // wait for a second digitalWrite(greenLedPin, LOW); // set the LED off delay(1000); // wait for a second }
おー、光った!! (動画は、BlackBerryからの投稿確認も含めて、次の機会に載せます。) これが私の最初のスケッチです。こんな単純なコードを書くだけでチカチカ制御!まさに自分レベルのマイコンです(笑)PICというと、色々作業がめんどくさそうで、敬遠気味だったのですが、これならいけそうです。
この投稿を楽しめましたか? もし良ければ、 コメントを残してお話をするか、 RSSフィードを購読 して、あなたのフィードリーダーに登録してみませんか?


Comments
コメントはまだありません。
コメントする