BASIC4MCU | 질문게시판 | 네오픽셀 스트립 방향
페이지 정보
작성자 도비 작성일2020-09-29 15:34 조회19,565회 댓글4건본문
손주에게 줄 광선검을 만들고 있습니다.
아두이노 예제 보고 작성했는데
켜는거나 끄는거나 같은 방향(0->72)이라..끌때 역방향(72->0)으로 꺼지게 하고 싶습니다.
이것만 잘 안되서 질문 드리게 됐습니다. 잘 부탁드립니다.
#include <Adafruit_NeoPixel.h>
#define BUTTON_PIN 2
#define PIXEL_PIN 6
#define PIXEL_COUNT 72
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);
bool oldState = HIGH;
int showType = 0;
void setup() {
pinMode(BUTTON_PIN, INPUT_PULLUP);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
bool newState = digitalRead(BUTTON_PIN);
if (newState == LOW && oldState == HIGH) {
delay(15);
newState = digitalRead(BUTTON_PIN);
if (newState == LOW) {
showType++;
if (showType > 5)
showType=0;
startShow(showType);
}
}
oldState = newState;
}
void startShow(int i) {
switch(i){
case 0: colorWipe(strip.Color(0, 0, 0), 50); // Black/off
break;
case 1: colorWipe(strip.Color(255, 0, 0), 50); // Red
break;
case 2: colorWipe(strip.Color(0, 0, 0), 50); // Black/off
break;
case 3: colorWipe(strip.Color(0, 255, 0), 50); // Green
break;
case 4: colorWipe(strip.Color(0, 0, 0), 50); // Black/off
break;
case 5: colorWipe(strip.Color(0, 0, 255), 50); // Blue
break;
}
}
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(15);
}
}
댓글 4
조회수 19,565master님의 댓글
master 작성일
void colorWipe_B(uint32_t c, uint8_t wait) { // 함수 이름이 다릅니다.
for(int i=(strip.numPixels()-1); i>0; i--){
strip.setPixelColor(i, c); strip.show(); delay(15);
}
}
반대로 켜줄 수 있는 함수를 하나 더 추가합니다.
master님의 댓글
master 작성일
void startShow(int i) {
switch(i){
case 0: colorWipe_B(strip.Color(0, 0, 0), 50); break; // Black/off
case 1: colorWipe(strip.Color(255, 0, 0), 50); break; // Red
case 2: colorWipe_B(strip.Color(0, 0, 0), 50); break; // Black/off
case 3: colorWipe(strip.Color(0, 255, 0), 50); break; // Green
case 4: colorWipe_B(strip.Color(0, 0, 0), 50); break; // Black/off
case 5: colorWipe(strip.Color(0, 0, 255), 50); break; // Blue
}
}
Black/off는 새로만든 함수를 호출합니다.
도비님의 댓글
도비
원하는데로 작동 잘 됩니다.너무 감사합니다..마스터님..
그런데 반대로 꺼지는데 0번 LED가 소등이 안되고 켜져 있는 상태로 되 있어요.
이건 어떻게 수정 하면 될까요?
master님의 댓글
master 작성일
void colorWipe_B(uint32_t c, uint8_t wait) {
for(int i=(strip.numPixels()-1); i>=0; i--){ // 이 라인이 수정되었습니다.
strip.setPixelColor(i, c); strip.show(); delay(15);
}
}