정보나눔

오픈소스하드웨어 프로젝트에 대한 다양한 정보를 나누는 공간입니다.

아두이노 네오픽셀에 관해 질문이 있습니다
예니 | 2016-12-02

 

저희가 지금 http://kocoafab.cc/make/view/668 강좌를 변형시켜서 저희만의 무드등을 만들고 있는데

소스 실행은 되고 불도 잘 들어오는데 이상하게 모든 네오픽셀이 앞에 1칸만 불이 켜지네요 ㅠㅠ

네오픽셀은 한 칸에 led 3개가 들어있고 정상적으로 작동하려면 15개의 led가 켜져야하는데

뭐가 문제인 걸까요? ㅠㅠ

아래에 소스 올리겠습니다 ㅜㅜ

 

 

 

#include
#include

 

Adafruit_NeoPixel background = Adafruit_NeoPixel(15, 3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel background1 = Adafruit_NeoPixel(15, 4, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel background2 = Adafruit_NeoPixel(15, 5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel background3 = Adafruit_NeoPixel(15, 6, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel background4 = Adafruit_NeoPixel(15, 7, NEO_GRB + NEO_KHZ800);

 

Adafruit_NeoPixel rain = Adafruit_NeoPixel(15, 8, NEO_GRB + NEO_KHZ800);     //날씨 LED_비
Adafruit_NeoPixel thunder = Adafruit_NeoPixel(15, 9, NEO_GRB + NEO_KHZ800);     //날씨 LED_번개
Adafruit_NeoPixel snow = Adafruit_NeoPixel(15, 10, NEO_GRB + NEO_KHZ800);     //날씨 LED_눈


boolean bBackground = false, bBackground1 = false,  bBackground2 = false,  bBackground3 = false,  bBackground4 = false;
boolean bRain = false, bThunder = false, bSnow = false, bRainbow = false;

 

float temperature; 
int reading; 
int lm35Pin = A0;

String sCommand = "";

 

void setup() {
  analogReference(INTERNAL);

  Serial.begin(9600);
  background.begin();
  background1.begin();
  background2.begin();
  background3.begin();
  background4.begin();
 
  background.setPixelColor(0, background.Color(0, 0, 0));
  background1.setPixelColor(0, background1.Color(0, 0, 0));
  background2.setPixelColor(0, background2.Color(0, 0, 0));
  background3.setPixelColor(0, background3.Color(0, 0, 0));
  background4.setPixelColor(0, background4.Color(0, 0, 0));
 
  background.show();
  background1.show();
  background2.show();
  background3.show();
  background4.show();

 
  beginNeoPixel();
}

 

 

void loop() {
  showWeather();
   temperature = getTemp();
 Serial.println(temperature);


   if (temperature < 10) changeColor(background.Color(224, 255, 255), 50);

    else if (temperature >= 10 && temperature <=13) changeColor(background.Color(0, 0, 255), 50);

    else if (temperature >= 13 && temperature <= 15) changeColor(background.Color(34, 139, 34), 50);

    else if (temperature >= 15 && temperature <= 17) changeColor(background.Color(65, 105, 0), 50);

    else if (temperature >= 17 && temperature <= 20) changeColor(background.Color(255, 20, 147), 50);

    else if (temperature > 20) changeColor (background.Color(255, 0, 0), 50);

 

    else changeColor(background.Color(255, 255, 255), 50);
   
    delay(1000);
 
  if (bBackground)  background.setPixelColor(0, background.Color(0, 0, 0));
  else if (bBackground) background.setPixelColor(0, background.Color(0, 0, 0));

 

    if (bBackground1)  background1.setPixelColor(0, background1.Color(0, 0, 0));
  else if (bBackground1) background1.setPixelColor(0, background1.Color(0, 0, 0));

 

      if (bBackground2)  background2.setPixelColor(0, background2.Color(0, 0, 0));
  else if (bBackground2) background2.setPixelColor(0, background2.Color(0, 0, 0));

 

      if (bBackground3)  background3.setPixelColor(0, background3.Color(0, 0, 0));
  else if (bBackground3) background3.setPixelColor(0, background3.Color(0, 0, 0));

 

      if (bBackground4)  background4.setPixelColor(0, background4.Color(0, 0, 0));
  else if (bBackground4) background4.setPixelColor(0, background4.Color(0, 0, 0));
   
  if (bRain)  rain.setPixelColor(0, rain.Color(0, 0, 0));
  else if (bRain) rain.setPixelColor(0, rain.Color(0, 0, 0));

 

    if (bThunder) thunder.setPixelColor(0, thunder.Color(0, 0, 0));
  else if (bThunder) thunder.setPixelColor(0, thunder.Color(0, 0, 0));

 

      if (bSnow) snow.setPixelColor(0, snow.Color(0, 0, 0));
  else if (bSnow) snow.setPixelColor(0, snow.Color(0, 0, 0));


}

 

void beginNeoPixel() {
  background.begin();
  background1.begin();
  background2.begin();
  background3.begin();
  background4.begin();
 
  rain.begin();
  thunder.begin();
  snow.begin();
}

 

void showNeoPixel() {
  background.show();
  background1.show();
  background2.show();
  background3.show();
  background4.show();

 

  rain.show();
  thunder.show();
  snow.show();
}

 

void changeColor(uint32_t c, uint8_t wait) {
  colorWipe(c, wait);
  colorWipe1(c, wait);
  colorWipe2(c, wait);
  colorWipe3(c, wait);
  colorWipe4(c, wait);
  colorWipe5(c, wait);
  colorWipe6(c, wait);
  colorWipe7(c, wait);
}

 

void colorWipe(uint32_t c, uint8_t wait) {
// for (uint16_t i = 0; i < background.numPixels(); i++)

{  
    if (bBackground) background.setPixelColor(0, c);
    else  background.setPixelColor(0, background.Color(0, 0, 0));
    background.show();
//    delay(wait);
 // }
}

 

void colorWipe1(uint32_t c, uint8_t wait) {
//  for (uint16_t i = 0; i < background.numPixels(); i++) {
   
    if (bBackground1) background1.setPixelColor(0, c);
    else  background1.setPixelColor(0, background1.Color(0, 0, 0));


    background1.show();


//    delay(wait);
 // }
}

 

void colorWipe2(uint32_t c, uint8_t wait) {
//  for (uint16_t i = 0; i < rain.numPixels(); i++)
{
 if (bRain)  rain.setPixelColor(0, c);
  else rain.setPixelColor(0, rain.Color(0, 0, 0));
    rain.show();
//    delay(wait);
  }
}


void colorWipe3(uint32_t c, uint8_t wait) {
//  for (uint16_t i = 0; i < thunder.numPixels(); i++)
{
    if (bThunder) thunder.setPixelColor(0, c);
  else if (bThunder) thunder.setPixelColor(0, thunder.Color(0, 0, 0));
  thunder.show();
//    delay(wait);
  }
}

 

void colorWipe4(uint32_t c, uint8_t wait) {
//  for (uint16_t i = 0; i < snow.numPixels(); i++)
{
      if (bSnow) snow.setPixelColor(0, c);
  else if (bSnow) snow.setPixelColor(0, snow.Color(0, 0, 0));
  snow.show();
//    delay(wait);
  }
}

 

void colorWipe5(uint32_t c, uint8_t wait) {
//  for (uint16_t i = 0; i < background.numPixels(); i++) {
   
    if (bBackground3) background3.setPixelColor(0, c);
    else  background3.setPixelColor(0, background3.Color(0, 0, 0));
    background3.show();
//    delay(wait);
 // }
}

 

void colorWipe6(uint32_t c, uint8_t wait) {
//  for (uint16_t i = 0; i < background.numPixels(); i++) {
   
    if (bBackground4) background4.setPixelColor(0, c);
    else  background4.setPixelColor(0, background4.Color(0, 0, 0));
    background4.show();
//    delay(wait);
 // }
}

 

void colorWipe7(uint32_t c, uint8_t wait) {
//  for (uint16_t i = 0; i < background.numPixels(); i++) {
   
    if (bBackground2) background2.setPixelColor(0, c);
    else  background2.setPixelColor(0, background2.Color(0, 0, 0));
    background2.show();
//    delay(wait);
 // }
}

 

 

void showWeather() {
  String sInput = getSerialInput();


  if (!isEmpty(sInput)) {
    Serial.println(sInput);
    int nPos = 0;
    String token = getToken(sInput, nPos);


    if (token == "on") {
      bBackground = true;
      bBackground1 = true;
      bBackground2 = true;
      bBackground3 = true;
      bBackground4 = true;
    }      

    
    else if (token == "off") {
      bBackground = bBackground1 = bBackground2 = bBackground3 = bBackground4 = false;
      bRain = bThunder = bSnow = false;
    }


    else if (token == "rain") {
      bBackground = true;
      bBackground1 = true;
      bBackground2 = true;
      bBackground3 = true;
      bBackground4 = true;
      bRain = true;
      bThunder = bSnow = false;
    }


    else if (token == "thunder"){
      bBackground = true;
      bBackground1 = true;
      bBackground2 = true;
      bBackground3 = true;
      bBackground4 = true;
      bThunder = true;
      bRain = bSnow = false;
    }


    else if (token == "snow") {
      bBackground = true;
      bBackground1 = true;
      bBackground2 = true;
      bBackground3 = true;
      bBackground4 = true;
      bSnow = true;
      bRain = bThunder = false;
    }
  }
}


double getTemp() {
  //온도값
  // 센서로 부터 자료값을 받습니다.
    reading = analogRead(lm35Pin);
    temperature = reading / 9.31;
    return temperature;
}

이전글   |    7805연결 제댇로 된건가요? 2016-12-02
다음글   |    아두이노 네오픽셀을 on, off 글자 입력으로 조정하고 싶습니다 ㅜㅜ... 2016-12-02