BASIC4MCU | 질문게시판 | 아두이노 네오픽셀 문제
페이지 정보
작성자 KSJ126 작성일2020-04-29 09:09 조회7,100회 댓글0건본문
#include <Adafruit_NeoPixel.h>
#define LED_PIN 6
#define NUM_LEDS 12
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600);
strip.begin();
strip.show();
}
void loop() {
Serial.println(analogRead(A0));
if (analogRead(A0) >600){
//Mode1
rainbow(20);
} else if (analogRead(A0) >300){
//Mode2
theaterChaseRainbow(20);
} else{
//Mode3
strip.Color(0,0,0);
strip.show();
}
delay(10);
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(wait);
}
}
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
strip.show();
delay(wait);
for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}
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모드가 변하게 할려고 하는데 (void loop부분)모드가 실행중에 아날로그값이 변해도 실행 완료후에 다시 모드변경되는데실행중에는 아날로그 값도 읽지 못하는것 같구요모드1 실행중에도 아날로그 값을 불러와 해당되는 모드로 바로 변경 되게 하고 싶어요불러온 아날로그 값이 현재 실행중인 모드 값이면 그대로 유지하구요3일째 해결방법 찾고 잇는데 초보라 도저히 방법이 없네요고수님들 부탁드립니다 ㅠㅠ
댓글 0
조회수 7,100등록된 댓글이 없습니다.