フルカラーLED「WS2812」
from https://learn.adafruit.com/pages/5682/elements/1711074/download
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define NUM_LEDS 8
#define BRIGHTNESS 5
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
int r; //赤色変数
int g; //緑色変数
int b; //青色変数
int i;
void setup() {
// End of trinket special code
strip.setBrightness(BRIGHTNESS);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
r = 255;
g = 255;
b = 255;
}
void loop() {
rainbaw();
}
void rainbaw() {
for (i = 0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, strip.Color(r, g, b));
}
strip.show();
delay(20);
}
Install the NeoPixel Library
If you are running Arduino IDE 1.6.1 or higher, you can install the library using the built in library manager, search for and install Adafruit_NeoPixel
Install and close out the Library manager.
from http://ch.nicovideo.jp/wolf64m/blomaga/ar710334
それではLED30個連結したリボンでは
--------------------------------------------------------------------------
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(30, 6, NEO_GRB + NEO_KHZ800);
int i; //個数の変数を増やしました
int r;
int g;
int b;
void setup() {
strip.begin();
strip.show();
}
void loop() {
for (i=0;i<strip.numPixels();i++){
// numPixelsで接続個数を帰すみたい
r=analogRead(1)/4;
g=analogRead(2)/4;
b=analogRead(3)/4;
strip.setPixelColor( i , strip.Color( r , g , b ));
strip.show();
delay(20);
}
}
---------------------------------------------------------------------
delayも入れて単純に30回送ってるのでグルッと回りますね
瞬間的に全体を変えたければ全部変えた後にdelayをいれれば良いかと
これだけのLEDをポート1個で済んじゃうなんて、便利だわー
って、前回も言ってた様な
どーやって使おうか
my simplest test code
#define PIN 6
#define NUM_LEDS 8
#define BRIGHTNESS 5
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
int r; //赤色変数
int g; //緑色変数
int b; //青色変数
int i;
void setup() {
// End of trinket special code
strip.setBrightness(BRIGHTNESS);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
r = 255;
g = 255;
b = 255;
}
void loop() {
rainbaw();
}
void rainbaw() {
for (i = 0; i < strip.numPixels(); i++)
{
strip.setPixelColor(i, strip.Color(r, g, b));
}
strip.show();
delay(20);
}
留言
張貼留言