BASIC4MCU | 질문게시판 | 아두이노 네오픽셀
페이지 정보
작성자 woody 작성일2020-04-27 21:10 조회23,128회 댓글5건본문
아두이노 초보입니다ㅠ
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + 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() {
// Some example procedures showing how to display to the pixels:
//colorWipe(strip.Color(255, 0, 0), 50); // Red
// delay(2000);
// if을 쓰면 되고
// colorWipe(strip.Color(0, 255, 0), 50); // Green
rainbow(200);
}
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<130; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
이 코들르 가지고 네오픽셀 LED 칩을 제어중입니다. 원하는 제어는 rainbow 함수를 이용하여 LED를 초록색에서 그라데이션으로 빨간색으로 변화하게 만들고 싶습니다..
혹시 가능하신분 계신가요ㅜ 아신다면 코드 수정좀 부탁드립니다ㅠ
댓글 5
조회수 23,128master님의 댓글
master 작성일
AVR+코드비젼으로 작성하고 있는 것 아닌가요?
질문 소스는 아두이노군요
woody님의 댓글
woody 작성일
코드비젼과 아두이노 둘 다 이용 중 입니다!!
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<130; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
이 코드를 이용하면 빨간색 -> 초록색으로 변화가 됩니다.
원하는 동작은 초록색 -> 빨간색인데 혹시 위에 코드 수정 가능하신지 여쭈어 봅니다.
master님의 댓글
master
네오픽셀이 동일하게 변하는 것이 아니고 레인보우 색상이 흐르듯이 변하는 함수입니다.
master님의 댓글
master 작성일
void green2red(uint8_t wait){
uint16_t i,c;
for(c=0;c<256;c++){
for(i=0; i<strip.numPixels(); i++)strip.setPixelColor(i,c,255-c,0);
strip.show();
delay(wait);
}
}
woody님의 댓글
woody
감사합니다ㅠ 아두이노도 쉽지많은 않네요,,,공부 열심히 해야되겠어요,,