2017. 8. 4. 19:07ㆍArduino
LED strip의 5V, DI(Digital In), GND 쪽에 해당하는 아두이노 5V, 6번 디지털 포트, GND를 점퍼선으로 연결해주면 된다.
LED strip을 사용하기 앞서 라이브러리를 다운받아야 하는데,
https://github.com/adafruit/Adafruit_NeoPixel
여기서 Clone or download를 눌러서 다운받은 폴더를 압축을 풀고, 아두이노 라이브러리 폴더에 넣어주면 된다.
그러면 아래 이미지와 같이 아두이노 예제로 들어가면 Adafruit NeoPixel 예제들을 볼 수 있다.
strandtest 예제를 골라서 바로 실행해도 되고, 조금 변경시켜서 이번 예제처럼 바꿔볼 수 있다.
일단 아래 이미지는 softpot 센서가 같이 달려있어서 복잡해 보이게 선을 연결했는데, 그냥 LED strip을 맨 위 이미지처럼 연결하면 된다.
방향을 꼭 화살표 방향으로 넣어줘야한다.
DI(Digital In) 쪽으로 연결시켜서 DO(Digital Out) 쪽으로 나오게 해야 불이 나온다.
#define PIN 6 6번 핀을 PIN으로 설정해주고
Adafruit NeoPixel strip = Adafruit NeoPixel(36, PIN, NEO_RGBW + NEO_KHZ800); 36개의 LED 갯수를 설정, 6번 PIN 설정, 사용중인 네오픽셀 종류에 맞게 설정
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #include <Adafruit_NeoPixel.h> #ifdef __AVR__ #include <avr/power.h> #endif #define PIN 6 Adafruit_NeoPixel strip = Adafruit_NeoPixel(36, PIN, NEO_RGBW + NEO_KHZ800); // IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input // and minimize distance between Arduino and first pixel. Avoid connecting // on a live circuit...if you must, connect GND first. 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 strip.begin(); strip.show(); // Initialize all pixels to 'off' } void loop() { for(int i=0;i<36;i++) { strip.setPixelColor(i,255,0,0,0); strip.show(); delay(50); } strip.show(); delay(1000); for(int i=0;i<36;i++) { strip.setPixelColor(i,0,255,0,0); strip.show(); delay(50); } strip.show(); delay(1000); for(int i=0;i<36;i++) { strip.setPixelColor(i,0,0,255,0); strip.show(); delay(50); } strip.show(); delay(1000); } | cs |
한 바퀴씩 색깔을 바꿔주는 간단한 코드를 입력하면 이런 식으로 출력이 되는 것을 볼 수 있다.
strip.setPixelColor(a,b,c,d,e); 으로 LED 색깔을 바꿔주면 된다.
적절한 delay를 줘서 눈에 보이게 LED 색이 바뀌게 설정해준다.
'Arduino' 카테고리의 다른 글
[아두이노 부품] 블루투스 통신 (0) | 2017.10.15 |
---|---|
[아두이노 부품] Arduino Adafruit NeoPixel control with Softpot 소프트팟으로 네오픽셀 조작 (0) | 2017.08.07 |
[아두이노 부품] Arduino vibration module 아두이노 진동 모듈 (0) | 2017.08.02 |
[아두이노 부품] Arduino turning on LED light with softpot (0) | 2017.08.01 |
[아두이노 부품] Arduino softpot membrane potentiometer 아두이노 압력감지센서 (0) | 2017.07.30 |