2021/08/01

Neo Pixelをarduinoで制御してみた

 Neo Pixelをarduinoで制御してみました。

NeoPixelを制御するにあたりFastLEDライブラリを使用しました。
特段理由はありませんww。
GitHub:https://github.com/FastLED/FastLED

ライブラリのインストールはarduino IDEのメニューの「スケッチ」から「ライブラリをインクルード」「ライブラリを管理」をクリック。
検索欄に「FastLED」を入力してFastLED by Daniel Garciaをインストール。


サンプルからBlinkを選択しちょいちょいとコードを修正し、実行。

#include <FastLED.h>

// How many leds in your strip?
#define NUM_LEDS 50 //LEDの数

// For led chips like WS2812, which have a data line, ground, and power, you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
// Clock pin only needed for SPI based chipsets when not using hardware SPI
#define DATA_PIN 3  //arduino出力Pin

// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() { 
    FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed
}

void loop() {
  // Turn the LED on, then pause
  for(int i= 0;i<NUM_LEDS;i++){
    leds[i] = CRGB::Red;
  }
  FastLED.show();
  delay(250);
  // Now turn the LED off, then pause
  for(int i= 0;i<NUM_LEDS;i++){
    leds[i] = CRGB(0,255,0);
  }
  FastLED.show();
  delay(250);
  // Now turn the LED off, then pause
  for(int i= 0;i<NUM_LEDS;i++){
    leds[i] = CRGB(0,0,255);
  }
  FastLED.show();
  delay(250);
  // Now turn the LED off, then pause
  for(int i= 0;i<NUM_LEDS;i++){
    leds[i] = CRGB(255,255,255);
  }
  FastLED.show();
  delay(250);
  for(int i= 0;i<NUM_LEDS;i++){
    leds[i] = CRGB::Black;
  }
}

そして、実行!!


LEDが思い通りに動いていない、というより赤色はしっかりと表示されていて
緑色が薄く、青色は全く光らなかった。。。
という事はもしかしてarduinoから出力の電源が足りないと思い
別電源を用意して再トライ!!

で上手く行きました!
とりあえず、これを使って何かを作る予定も無いので
今回はここまでです。


 NT金沢 2023に出展&見学に行きました! 久しぶりの更新です。。。 イメージ書道&あきにゃんさんの作品 書家さんが書かれた作品を3Dプリンタ等した作品。 面白いものから関心するものまで色々あります。 個人的には「頭をひねる」がツボです。 写真では分かりづらいですが、...