일단 무슨 기능인지 결과를 먼저 보자

<기능 추가한 동영상>

그렇다. 그냥 뺑글뺑글 도는 기능 추가한 것이다. 소스 코드에는 여러가지 흔적이 있지만 그냥 이걸 보여주는 걸로 만족 ㅋ


아래는 작업 과정이다.

이랬던 뒷면이 

<오크통뱅크 상판 뒷면_작업 하기전>

이렇게 바뀌었다. --.--

<오크통뱅크 상판 뒷면_작업 후>

막손이라 정리가 잘 안된다. <- 잘 안된거 숨기기 위해 글씨는 작게......


원래 오크통네오픽셀아두이노 나노가 들어갈 자리는 없다. 그런데 들어가 있다. 이유는 간단하다.

처음 배터리팩과 오크통을 구매할 당시 어거지로 넣다가 뺄수도 없고 완벽하게 넣을 수도 없는 중간에

걸린 상황이 되어 눈물(ㅠㅠ)을 머금고 오크통을 분해 했다. 조립하는 과정에서 공간을 만든다고 바닥을

아래의 사진처럼 만들었다.

<오크통뱅크 바닥>


분해된 오크통 재활용 하다보니 공간이 남아서 아두이노 나노를 넣을수 있었다. 그러나 꽉 찬다...... 


이제 소스 코드를 보자!

기본에 있는 예제 소스를 기본으로 몇개 추가 하고 수정 했다.


#include <Adafruit_NeoPixel.h>

//#include <MsTimer2.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(13, PIN, NEO_GRB + NEO_KHZ800);

uint32_t oakStrip[13] = {strip.Color(0,255,0) //초록색

                        ,strip.Color(0,255,0)       //단색으로 돌릴대는 이부분 수정해 주면 된다. 적어도 앞 부분에 5개 정도 색을 지정해야

                        ,strip.Color(0,255,0)       //이쁘게 나온다.

                        ,strip.Color(0,255,0)

                        ,strip.Color(0,255,0)

                        ,strip.Color(0,0,0)

                        ,strip.Color(0,0,0)

                        ,strip.Color(0,0,0)

                        ,strip.Color(0,0,0)

                        ,strip.Color(0,0,0)

                        ,strip.Color(0,0,0)

                        ,strip.Color(0,0,0)

                        ,strip.Color(0,0,0)

};

int onStrip[13] = {1,1,1,1,1,0,0,0,0,0,0,0,0}; //

int currentPos = 10;

int fade = 2;


// 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


  Serial.begin(9600);

  strip.begin();

  strip.show(); // Initialize all pixels to 'off'

  //MsTimer2::set(60, onFade); //숨쉬는 기능을 적용할려면 이 부분 주석을 풀어 부면 된다.

  //MsTimer2::start();

}


void loop() {

  

  //onColor(); //단색으로 돌리기

  

  rainbow(60); //무지개색으로 돌리기


}


void onColor()

{

  for(int j = 13 ; j > 0 ; j--){

    for(int i = 0 ; i < strip.numPixels() ; i++)

    {

     strip.setPixelColor(i, oakStrip[(j+i)%strip.numPixels()]);

    }

    strip.show();

    delay(60);

  }

}


void rainbow(uint8_t wait) {

  uint16_t i, j;


  //strip.setBrightness(0);

  //currentPos = 0;


  for(j=0; j<256; j++) {

    for(i=0; i<strip.numPixels(); i++) {

      if(onStrip[(j+i)%13] == 1)

      {

        strip.setPixelColor(i, Wheel((i+j) & 255));

      }

      else

      {

        strip.setPixelColor(i, 0);

      }

    }

    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);

}


void onFade() // 숨시기 기능 함수

{

  if( currentPos < 3 || currentPos > 125 )

  {

    fade = fade * (-1);

  }

  currentPos = currentPos + fade;

  strip.setBrightness(currentPos);

  Serial.println(currentPos);

}


소스코드는 이렇다. 그냥 쓰면 된다. 더 좋은 방법이 있다면 댓글로 살짝 알려 줬으면 좋겠다. 그래야 나도 보고 배우니까^^

여기에 추가 기능 하다 더 넣고 싶은게 있다. 배터리 전압을 체크 하여 배터리 전압대응하는 색으로 표시하는 기능이다.

mcu 자체적으로 내부 전압을 알수 있다고 하는데...... 검색해봐야 겠다.


오크통뱅크 자료는 에다이카페에 있다. 


___LED.ino

Adafruit_NeoPixel-master.zip


반응형
블로그 이미지

두리뭉실:해피파인더그룹

컴퓨터 코치 두리뭉실

,