프라모델

[LED DIY] RG Unicorn Banshee 유니콘 밴시

여우래비 2021. 7. 21. 06:13
반응형

안녕하세요, 여우래비 입니다.

요즘 장마기간이라 아무래도 습도가 높다보니, 제 주력인 마커를 사용한 애니도색보다는 LED 에 보다 집중하게 됩니다.

습도가 높으면 마감재를 뿌렸을 때 백화 현상이 거의 100% 발생하거든요.

 

여. 하. 튼.

지난번 RG Unicorn Banshee 하체에 이어 상체도 마무리를 했습니다!

하체만 홀로 외로이..

당초 디스트로이 모드만 염두에 두고 작업했기 때문에, 하체, 특히 허벅지 부분의 변형 기믹은 포기한 것에 비해,

상체의 경우는 변형이 100% 가능하도록 작업을 완료했습니다.

다만 머리의 경우 LED Strip 을 넣을 공간이 그리 많지 않아 변형시 일부 파트를 제거해야 합니다만, 변형은 가능하니 ㅎㅎ

의외로, 부품분할이 되어 있어서 그런지 HG 보다 작업이 훨씬 용이하였습니다. 

가장 까다로운 부분은 역시 허벅지인데, 조금더 고민을 해봐야 할 것 같습니다.

 

사실, 이번 RG 유니콘 밴시를 작업한 것은 RG 페넥스를 위한 연습입니다.

(미안 밴시..)

최종 목표는 RG 페넥스에 변형이 가능하도록 LED 기믹을 추가하는 것.

'21.7월에 RG 페넥스를 주문했고, 11월에 배송되므로 겨울에는 PG 페넥스 못지 않은 작품이 나오기를 스스로 기대해 봅니다. ^^

 

  완성 사진

 

  회로 구성

 

설명 드렸듯이, 일단 기본적인 부품들은 구비가 되어 있어야 합니다.

즉, 아두이노, LED Strip, 빵판, 점퍼케이블 및기타 납땜 공구들은 필수 입니다.

 

 

건담 쪽에는 아래와 같이 작업해 주었습니다.

(귀찮아서 그라운드만 연결하였습니다. 그 와중에 왼팔은 배선이 틀렸네요..ㅎㅎ 감안하시기 바랍니다.)

사실, 건담에 LED 매립하는 작업이 가장 큰일 중 하나입니다.

 

  소스 코드

 

아래의 코드는 여러군데 웹서칭을 통해 조합한 것으로,

스위치를 누를 때 마다 색상이 적색->녹색->청색->백색->->Off 순으로 변화합니다.

#include <SoftwareSerial.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define dataPin 6  // Set Pin 6 for Data

Adafruit_NeoPixel ledstripTest = Adafruit_NeoPixel(7, dataPin, NEO_GRB + NEO_KHZ800);

// this constant won't change:
const int  buttonPin = 2;    // the pin that the pushbutton is attached to
const int ledPin = 13;       // the pin that the LED is attached to

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button
int i=0;

void shutAllLedStrip() {
  for(int i=0; i<=ledstripTest.numPixels(); i++) {
    ledstripTest.setPixelColor(i, ledstripTest.Color(0, 0, 0));
  }
    ledstripTest.show();
}

void shutAllLedStrip_R1 (uint32_t color, int wait) {
  for(int i=ledstripTest.numPixels(); i>=0; i--) { // For each pixel in strip...
    ledstripTest.setPixelColor(i, color);         //  Set pixel's color (in RAM)
    ledstripTest.show();                          //  Update strip to match
    delay(wait);                           //  Pause for a moment
  }
}

void sequenceLed(uint32_t color, int wait) {
  for(int i=0; i<=ledstripTest.numPixels(); i++) { // For each pixel in strip...
    ledstripTest.setPixelColor(i, color);         //  Set pixel's color (in RAM)
    ledstripTest.show();                          //  Update strip to match
    delay(wait);                           //  Pause for a moment
  }
}

void shutDown() {
    for (int i=125; i>=0; i--) {
      ledstripTest.setPixelColor(0, i, 0, 0);
      ledstripTest.setPixelColor(1, i, 0, 0);
      ledstripTest.setPixelColor(2, i, 0, 0);
      ledstripTest.setPixelColor(3, i, 0, 0);
      ledstripTest.setPixelColor(4, i, 0, 0);  
      ledstripTest.setPixelColor(5, i, 0, 0);  
      ledstripTest.setPixelColor(6, i, 0, 0);  
      delay (10);
      ledstripTest.show();
      buttonState = digitalRead(buttonPin);
            Serial.println("pass breathRed1");    
      if (buttonState == digitalRead(buttonPin)) break;

    }
      buttonState = digitalRead(buttonPin); 
      if (buttonState != digitalRead(buttonPin))exit(0);
}


// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
void rainbow(int wait) {
  while(buttonState == lastButtonState){

  // Hue of first pixel runs 5 complete loops through the color wheel.
  // Color wheel has a range of 65536 but it's OK if we roll over, so
  // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
  // means we'll make 5*65536/256 = 1280 passes through this outer loop:
  for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {

    for(int i=0; i<ledstripTest.numPixels(); i++) { // For each pixel in strip...

      // Offset pixel hue by an amount to make one full revolution of the
      // color wheel (range of 65536) along the length of the strip
      // (strip.numPixels() steps):
      int pixelHue = firstPixelHue + (i * 65536L / ledstripTest.numPixels());
      // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
      // optionally add saturation and value (brightness) (each 0 to 255).
      // Here we're using just the single-argument hue variant. The result
      // is passed through strip.gamma32() to provide 'truer' colors
      // before assigning to each pixel:
      ledstripTest.setPixelColor(i, ledstripTest.gamma32(ledstripTest.ColorHSV(pixelHue)));

      }
      ledstripTest.show(); // Update strip with new contents
      buttonState = digitalRead(buttonPin);
      delay(wait);  // Pause for a moment
      if (buttonState != digitalRead(buttonPin)) break;
   }
    buttonState = digitalRead(buttonPin);
    if (buttonState == digitalRead(buttonPin)) break;
  }
}

void setup() {
  ledstripTest.begin();
  shutAllLedStrip();
  pinMode(buttonPin, INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
  Serial.begin(9600);
  Serial.println("Test Start");
}

void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == LOW) {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter);
    } else {
      // if the current state is LOW then the button
      // wend from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state,
  //for next time through the loop
  lastButtonState = buttonState;


  // turns on the LED every four button pushes by
  // checking the modulo of the button push counter.
  // the modulo function gives you the remainder of
  // the division of two numbers:
  if (buttonPushCounter % 6 == 0) {
    digitalWrite(ledPin, HIGH);
    shutAllLedStrip_R1(ledstripTest.Color(0, 0, 0), 50);
  } 
    if (buttonPushCounter % 6 ==1) {
    digitalWrite(ledPin, LOW);
    sequenceLed(ledstripTest.Color(255, 0, 0), 50);
  } 
    if (buttonPushCounter % 6 ==2) {
    digitalWrite(ledPin, LOW);
    sequenceLed(ledstripTest.Color(0, 255, 0),50);
  }
    if (buttonPushCounter % 6 ==3) {
    digitalWrite(ledPin, LOW);
    sequenceLed(ledstripTest.Color(0, 0, 255), 50);
  }
    if (buttonPushCounter % 6 ==4) {
    digitalWrite(ledPin, LOW);
    sequenceLed(ledstripTest.Color(30, 30, 30), 50);
  }

    if (buttonPushCounter % 6 ==5) {
    digitalWrite(ledPin, LOW);
    rainbow(10);
  }

}// eof

LED_Strip_Switch_Success1_Seq_excuted.zip
0.00MB

 

위 코드는 가장 기본적인 코드이며, 만약 화려한 변화를 적용하고 싶다면 아래 사이트를 방문하여 코드를 다운받을 수도 있습니다.  아래 사이트는 웹 서칭 중 찾은 주옥같은 곳으로, LED Strip 제어 뿐 만 아니라 아두이노를 이용한 거의 모든 응용에 대한 예제 및 하드웨어 구성이 무료로 제공됩니다.

 

Arduino – All LEDStrip effects in one (NeoPixel and FastLED)

This article shows how you can combine all LEDEffects, for your ledstrip and Arduino, as discussed in a previous article, can be combined into one single sketch, allowing you to use a button to toggle effects.

www.tweaking4all.com

 

아래 그림을 클릭해서 다운받을 수도 있고, 위의 사이트를 방문해도 됩니다.

 

마찬가지로 작업기 및 작동 영상을 아래와 같이 제작하였으니 많은 시청 바랍니다.

 

이번 포스팅 끝.

반응형