Arduino sketch

Ask and answer questions, share tips and resources for installing lighting and other electronics in your models.

Moderators: Sparky, Moderators

Post Reply
TShark
Posts: 82
Joined: Mon Oct 26, 2009 3:33 pm

Arduino sketch

Post by TShark »

I have completed the preliminary bench tests of my bussard lighting and running lights for my 18" (1:650 scale) TOS Enterprise. I call these "Shadow Bussards" because the animation of the rotors is done by LED animation causing movement of the rotor shadows within the bussard domes. Compared to motorized rotors this setup is much simpler to wire-up and easier to physically construct within the nacelles. Additionally the animation speed of both nacelles is exactly the same and it is completely silent. My initial bench test was with an Arduino Uno, but I recently used a Sparkfun Arduino Pro mini with no problems. The entire system is running off of a 5 volt wall wart. This bussard lighting may also work for smaller scales such as the 1/1000 scale TOS Enterprise.

Here is a video of my bench test:

https://www.youtube.com/watch?v=1aFZbrLPVJ8

Here is a tutorial on the Shadow Bussard construction:

https://www.youtube.com/watch?v=_1w1n-JKdxg&t=11s

The colors of the bussards and animation look better in real life, but the video gives you an idea of what I am going for.

Here is the parts list for the Shadow Bussards:
1) Arduino compatible board 5volt 16Mhz

2) Adafruit NeoPixel LED Side Light Strip - Black 120 LED PRODUCT ID: 3634

3) 1 ea 1000uf capacitor and 1 ea 470 Ohm resistor for LED strip power hook-up (per Adafruit's Neopixel tutorial)

4) 120VAC to 5VDC/2 amp power adapter

5) JT-Graphics Bussard Collectors Part# JTR-033 (I have also tried the DLM bussard collectors and they look good too.)
*Note: The original nacelle caps can be used by cutting off the domes and replacing them with 7/8" (22.2mm) Clear domes from KitKraft part#303851.

6) Paragrafix - STAR TREK 18 INCH ENTERPRISE ACCURIZING PHOTOETCHED SET - PGX116 (for the rotors)

The Neopixel strip is cut into two segments of 19 LED's each. Three leads are soldered to one end of each segment. On each segment two of these leads are for positive and negative power with the third lead being for data (as per Adafruit's Neopixel tutorial). The Arduino uses just one pin to send data to both segments. These segments are then rolled to fit within the nacelles, hot glued on the back side to keep shape, then placed one segment per nacelle.

With this set-up you now have 19 LED's in each nacelle that are individually addressable (you can control color, brightness, and speed of animation) all within the Arduino sketch.

After placing the Neopixel rolls in each nacelle, I ground out the center of the JT-Graphics bussard caps so that the LED's could shine through it. I used the top parts of the Paragraphix photoetch rotors and placed them inside the bussard caps. The rotors need to be placed back about 1/8 inch from the inner surface of the bussard domes so that the shadow is cast on the inside of the domes. You can play with the distances of the rotors to dome to find the best look. A light sanding of the inside of the domes with 220 grit sand paper frosted the domes enough for me.

The Arduino sketch I used is a modified TheaterChase animation combined with a running light sketch provided by Ross Waddell. To add the running light feature to the TheaterChase sketch required the removal of the timing delays used by Adafruit's stock Neopixel TheaterChase sketch. You will have to download the following libraries to your Arduino IDE program:

1) Adafruit Neopixel library. Instructions found here: https://learn.adafruit.com/adafruit-neo ... stallation
2) LEDfader and Curve library found here: https://github.com/jgillick/arduino-LEDFader

After installing the libraries just select the code below, right click and copy it. Then paste it in an Arduino sketch.
---------------------------------------------------------------

Code: Select all

#include <Curve.h>                    // Part of library below; helps make fade in/out more smooth
#include <LEDFader.h>                 // Library used to fade running lights LEDs without using delay()

#define FADE_TIME_RUN_LTS 125    // Number sets speed of running lights fade up and down
LEDFader ledRunLts;

#define LED_RUN_LTS_PIN 10
const int LED_RUN_LTS_ON_DUR = (1500 - FADE_TIME_RUN_LTS*2);  // Running lights time on in milliseconds
                                                              // This takes into account the fade in/down time
const int LED_RUN_LTS_OFF_DUR = 500;  // Running lights time off in milliseconds
boolean ledRunLtsState = HIGH;

#include <Adafruit_NeoPixel.h>

#define PIXELSPIN   6     //  Output pin on Arduino for Neopixel data
#define NUMPIXELS   19    //  Number of pixels in a segment
#define CALIBRATIONTIME 20000

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIXELSPIN, NEO_GRB + NEO_KHZ800);

unsigned long pixelsInterval=110;  // Speed of TheaterChase higher # means slower
unsigned long theaterChasePreviousMillis=0;

int theaterChaseQ = 0;

uint16_t currentPixel = 0;// what pixel are we operating on

void setup() {
  currentPixel = 0;
 
  pixels.begin(); // This initializes the NeoPixel library.
  pixels.show(); // This sends the updated pixel color to the hardware.

  ledRunLts = LEDFader(LED_RUN_LTS_PIN);
  ledRunLts.set_curve(&Curve::exponential);
  ledRunLts.fade(255,FADE_TIME_RUN_LTS);
}

void loop () {
    unsigned long ms = millis();     
      ledRunLts.update();
      blinkLED_Run_Lts(ms);
               
        if ((unsigned long)(millis() - theaterChasePreviousMillis) >= pixelsInterval) {
          theaterChasePreviousMillis = millis();
          theaterChase(pixels.Color(65, 15, 5)); // Base color of bussards
        }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c) {
  for (int i=0; i < pixels.numPixels(); i=i+3) {
      pixels.setPixelColor(i+theaterChaseQ, c);    //turn every third pixel on
     if (i+theaterChaseQ==13) {pixels.setPixelColor(13, 0, 0, 60); // set pixel #13 to blue in animation
          }
          if (i+theaterChaseQ==9) {pixels.setPixelColor(9, 0, 40, 0); // set pixel #9 to green pixel in animation
          }
 }
    pixels.show();
    for (int i=0; i < pixels.numPixels(); i=i+3) {
      pixels.setPixelColor(i+theaterChaseQ, 0);        //turn every third pixel off
    }
    theaterChaseQ++;
    if(theaterChaseQ >= 3) theaterChaseQ = 0;
}
void blinkLED_Run_Lts(unsigned long currentTime)
{
/*

  Function has parameter (unsigned long currentTime) to determine if it's now time to blink on or off the LED.

  In this case, rather than simply turn on or off the LED a fade is initiated using LEDFader. But, LED will not
  turn off or on again until the specified time has elapsed.

  Returns: nothing

*/

  static unsigned long msLast1;

  if (currentTime - msLast1 >= (ledRunLtsState ? LED_RUN_LTS_ON_DUR : LED_RUN_LTS_OFF_DUR)) {
      ledRunLtsState = !ledRunLtsState;
     
      if(ledRunLtsState == HIGH)
      {
        // Fade up


        ledRunLts.fade(255, FADE_TIME_RUN_LTS); // Number sets brightness of running lights
      }
      else
      {
        // Fade down


        ledRunLts.fade(0, FADE_TIME_RUN_LTS);
      }
     
      msLast1 = currentTime;
  }
------------------------------------------------------

Forgive me if the code is a bit clunky as I am still new to the Arduino programming.

Feel free to use this info for private use. I will keep you updated as I progress.

Tshark
Last edited by TShark on Thu Aug 02, 2018 7:39 am, edited 1 time in total.
TShark
User avatar
naoto
Posts: 29236
Joined: Fri Jul 12, 2002 3:22 pm
Location: Temple City, California, USA

Re: Arduino sketch

Post by naoto »

BTW, on this board you can surround computer code with the tags [code] and [/code]

If you enter text in message like:
[code]
main()
{
  puts("Hello, world!");
}
[/code]


You get this when displayed:

Code: Select all

main()
{
  puts("Hello, world!");
}
The text between the tags will show up in a monospace typeface and will also display leading spaces (which may not add much for the computer, but does make it more readable for humans). If the program was in Python, then indentation *is* important.
Naoto Kimura
木村直人
TShark
Posts: 82
Joined: Mon Oct 26, 2009 3:33 pm

Re: Arduino sketch

Post by TShark »

Thank you I edited the code. :)
TShark
TShark
Posts: 82
Joined: Mon Oct 26, 2009 3:33 pm

Re: Arduino sketch

Post by TShark »

Here is a final video showing the Shadow Bussards on the finished model and a brief description of the basic components I used:

https://www.youtube.com/watch?v=SbNkfDAjDuQ&t=26s

Hope you enjoy
TShark
Post Reply