WS2812B LEDテープのプログラムの続き
WS2812Bを買って最終的にはサウンドメーター作成を目指していますが、LEDテープの色の制御についてです。配線は、前につかったものをそのまま使います。
#include <Adafruit_NeoPixel.h>
#define PIN 6 // On Trinket or Gemma, suggest changing this to 1
#define NUMPIXELS 30 // Popular NeoPixel ring size
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRBW + NEO_KHZ800);
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels
void setup() {
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
}
void loop() {
pixels.clear(); // Set all pixel colors to 'off'
for (int i = 0; i < NUMPIXELS; i++) { // For each pixel...
pixels.setPixelColor(i, pixels.Color(0, 64, 0));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(DELAYVAL); // Pause before next pass through loop
}
}
スケッチは上記になります。
このままだと30個のLEDが緑に順番に光ります。
17行目の pixels.setPixelColor(i, pixels.Color(0, 64, 0));の数字を変更すると色が変わります。(64,0,0)で赤、(0,0,64)で青、(64,64,64)で白です。
本日は以上です。(^^)
この記事が気に入ったらサポートをしてみませんか?