目的
NeoPixel 1515 LEDテープをarduinoで光らせた際の備忘録です
準備
Arduino Uno
NeoPixel 1515 LEDテープ
Adafruit_NeoPixelライブラリをArduinoIDEにインストールします
回路図
Arduino - NeoPixel
5V - 5V
PIN6 - D0
GND - GND
※ピンを半田付けする際に、向きがあるようです。
テープに印字されている矢印(→)の向きに従って半田付けするようにしましょう。
コード
サンプルコードを利用します。
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
# include <Adafruit_NeoPixel.h>
# ifdef __AVR__
#include <avr/power.h>
# endif
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
# define PIN 6
// How many NeoPixels are attached to the Arduino?
# define NUMPIXELS 16
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 500; // delay for half a second
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
# if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
# endif
// End of trinket special code
pixels.begin(); // This initializes the NeoPixel library.
}
void loop() {
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
for(int i=0;i<NUMPIXELS;i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
テスト
光ればOKです。
adafruit neopixelを入手 pic.twitter.com/NdDMwpkpYp
— st (@st17890027) February 1, 2020
追記
こちらを参考にさせて頂きランダムに光るプログラムを作成しました。
# include <Adafruit_NeoPixel.h>
# define PIN 6
# define NUMPIN 75
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIN, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
Serial.begin(9600);
}
void loop() {
int sensor0 = abs(analogRead(A0)-512);
//回数
for(int i=0; i<NUMPIN; i++){
if(sensor0>100){
int r = random(0,NUMPIN);
int cR = random(0,256);
int cG = random(0,256);
int cB = random(0,256);
strip.setPixelColor(r, strip.Color(cR,cG,cB));
}
strip.show();
}
// //All off
for(int i=0; i<NUMPIN; i++){
strip.setPixelColor(i, strip.Color(0,0,0));
strip.show();
}
Serial.println(sensor0);
}
adafruit neopixel ランダムに光るバージョン pic.twitter.com/9gVjBDJkov
— st (@st17890027) February 1, 2020
CodingError対策
線を繋いでいるが、NeoPixelが光らない
ピンを半田付けする際に、向きがあるようです。
テープに印字されている矢印(→)の向きに従って半田付けするようにしましょう。
参考
超薄型NeoPixel 1515 LEDテープ (幅4mm、長さ0.5m、75個LED)
NeoPixelをMaxで光らせるまで
Adafruit_NeoPixel
Arduinoに接続したNeoPixelの色と明るさをシリアル通信で制御する
ライブで大活躍!音に反応して光るサバゲーマスク!
春の電子回路WS
ArduinoでLEDテープライトを光らせる
ArduinoでLEDテープを光らせて遊ぶ
【Arduino】LEDシリアルテープを光らせる