Welcome, %1$s. Please login or register. - Did you miss your activation email?

Login with username, password and session length
 

Author Topic: [How To - Arduino Nano] JJverse Starfleet Starship Running & Strobe Lights  (Read 1858 times)

Offline Gadgetron_3000

  • Admiral
  • *****
  • Posts: 1160
Hi, Everyone.

Here is another Arduino sketch.  This time for JJverse Starfleet Starship Running and Strobe Lights.

First, if you need install an Arduino board and the Arduino Software (IDE), you can check out my previous post for a guide: http://scifimodelaction.com/sfmaforum/index.php?topic=4793.msg64348#msg64348.

Now onto programming the attached board.  This Arduino sketch will have the Nano control two LEDs: one 'double-blinking' running light and one strobe light.

The alternate-reality 'JJprise' has 10 double-blinking running lights in the primary hull and 3 strobe lights (one behind the bridge, one at the rear of the secondary hull, and one at the bottom of the secondary hull).  This sketch sets up two different outputs only which then relies on the use of transistors and external power to drive the actual 13 LEDs.  I'll update this thread again in the future after I get in some transistors to create the complete setup.

This is intended for the Revell Germany 1:500 JJverse Enterprise.

1. Copy the following code:
Quote
/*
  JJverse Starfleet Starship Running and Strobe Lights:

    - Turns on 'double-blinking' running light LED sequence: on for 0.03 second (30 milliseconds),
      off for 0.12 second (120 milliseconds), on for 0.03 second, then off for 3 seconds
      (3000 milliseconds), repeatedly.

    - Turns on strobe lights LED sequence: fades on, then off for 1.5 seconds (1500 milliseconds),
      repeatedly.

    - 1 second = 1000 milliseconds

    - JJverse starship blink / flash rates reference video can be found on YouTube
      (http://youtu.be/A0i72CsaL2I).

    - Based on original sketch by Hugh Beauchamp
      (http://www.therpf.com/showthread.php?t=218311&p=3371496&viewfull=1#post3371496).

  NOTE:

    There are ten 'double-blinking' running lights on the primary hull - 5 at the upper primary hull
    and 5 at the lower primary hull.

    There are three strobe lights - 1 behind the bridge, 1 at the rear of the secondary hull, and
    1 at the bottom of the secondary hull.

*/

// set LED pins
const int doubleblink = 12;   //double-blinking running light on pin 12
const int pulse = 10;         //strobe light on pin 10 (PWM output)

// set variables
int blinkstate = LOW;

long previousMillis = 0;     // stores last time LED updated

long blinkDuration = 30;     // blinking strobe on time
long blinkInterval = 120;    // blinking strobe time between short blinks
long blinkWait = 3000;       // blinking strobe time between cycles
long pulseWait = 1500;       // pulsing strobe time between cycles
long pulseSpeed = 3;         // pulsing strobe delay for each fade level. shorter times mean a faster fade
long pulseOn = 0;            // pulsing strobe time to hold at maximum brightness
int blinkno = 0;             // blink counter stores the number of elapsed flashes

int brightness = 0;          // how bright the pulse LED is
int maxbrightness = 255;     // what the maximum brightness of the pulsing strobe is
int fadeAmount = 5;          // how many points to fade the LED by

void setup()
{
  pinMode (doubleblink, OUTPUT);
  pinMode (pulse, OUTPUT);
}

void loop()

// set current time to time since sketch began running
    unsigned long currentMillis = millis();

// check if time elapsed is greater than strobe time between cycles
    if(currentMillis - previousMillis > blinkWait && blinkno == 0) {

        previousMillis = currentMillis;                     // save the time the LED switched

        blinkstate = HIGH;                                  // set LED state
   
        digitalWrite(doubleblink, blinkstate);              // set the LED
   
        blinkno = blinkno + 1;                              // increment blink counter
    }
 
// check if time elapsed is greater than strobe on time
    if(currentMillis - previousMillis > blinkDuration && blinkno == 1) {
        previousMillis = currentMillis;   
        blinkstate = LOW;
        digitalWrite(doubleblink, blinkstate);
        blinkno = blinkno + 1;
    }
 
// check if time elapsed is greater than strobe interval
    if(currentMillis - previousMillis > blinkInterval && blinkno == 2) {
        previousMillis = currentMillis;   
        blinkstate = HIGH;
        digitalWrite(doubleblink, blinkstate);
        blinkno = blinkno + 1;
    }

// check if time elapsed is greater than strobe on time - might be able to reuse statement above
    if(currentMillis - previousMillis > blinkDuration && blinkno == 3) {
        previousMillis = currentMillis;   
        blinkstate = LOW;
        digitalWrite(doubleblink, blinkstate);
        blinkno = blinkno + 1;
    }
 
// check if time elapsed is greater than pulse interval 
    if(currentMillis - previousMillis > pulseWait && blinkno == 4) {
        // fade up pulse LED
        for(brightness = 0; brightness <=maxbrightness; brightness+=fadeAmount) {       
            analogWrite(pulse, brightness);                  // set pulse LED brightness
            delay (pulseSpeed);                              // wait to see fade effect
        }
        delay (pulseOn);                                     // wait while LED is at maximum brightness
        // fade down pulse LED
        for(brightness = maxbrightness; brightness >=0; brightness-=fadeAmount) {
            analogWrite(pulse, brightness);
            delay (pulseSpeed);
        } 
        blinkno = 0;                                         // reset blink counter to zero
    }
}                                                            // end of loop
2. Replace the existing code in the Arduino software window with the copied code.
3. Save the sketch.  NOTE: for your reference, saved Arduino sketches are located in the C:\Users\<Windows user name>\Documents\Arduino folder.
4. Click the 'Verify' check-mark icon to allow the Arduino software to compile the code and check for issues.  When finished, the software status bar will say 'Done compiling.'
5. Click the 'Upload' right-arrow icon to allow the Arduino software to program the Nano.  When finished, the software status bar will say 'Done uploading.'

And that's it!  Easy!

Here is a pin diagram picture that will show where to make all your connections:



Don't forget to use resistors for your LEDs when doing your initial testing with just the two LEDs (one for each pin specified in the sketch)!  You should be able to use a 9- or 12-volt power supply.  For the purposes of my testing, I used the computer's 5-volt USB port that the Nano was already connected to.

I used researched timing for the LED blink / flash effects, but you can always change the values to whatever you want to fit your needs.

:)
"They've done studies, you know.  60% of the time, it works every time."

-----

Google+: https://plus.google.com/109660073537038906328

Offline Gadgetron_3000

  • Admiral
  • *****
  • Posts: 1160
Re: [How To - Arduino Nano] JJverse Starfleet Starship Running & Strobe Lights
« Reply #1 on: February 27, 2015, 01:43:15 pm »
I posted a demo of the JJverse Starfleet Starships Running & Strobe Lights limited test setup on YouTube...

http://youtu.be/GnBVfvwM9WM

:)
"They've done studies, you know.  60% of the time, it works every time."

-----

Google+: https://plus.google.com/109660073537038906328

Offline podmore71

  • Ensign
  • *
  • Posts: 23
Hi Gadgetron

I've just bought myself the Revell JJPrise kit as my first kit to get back into this wonderful hobby. Yeah I know. I must be nuts lol.

I'm planning on lighting it all up and using the nano to control all the lighting and sound effects I want to put into it, so finding this sketch and right up for it is a god send. Thank you very much.

Did you manage to complete the setup with the transistors you mentioned?

Thanks
Andy

Offline madmonk

  • Commander
  • ***
  • Posts: 222
That's a great sketch but with the Nano seems a bit overkill to produce two flashing outputs.

I use an ATtiny85 8pin processor programmed using an Uno for the Strobe and Running lights.  On the saucer I use 5 LEDs with 2x 1.0mm fibre strands for the running lights and a 2mm lighthouse LED for the bridge strobe.  On the secondary hull I use a single 3mm LED with  2x 1.0mm fibre for the strobes.

There are also running lights on the rear top surface of the nacelles.

The ATtiny will happily run the 9 LEDs at 5V all day.  The programme is very simple and as it is only doing the lights you can use the delay command.

Quote
#include <LedFlasher.h>

// set up some LEDs
LedFlasher flash1 (1, 2700, 300);
int flash2 = 4;

void setup() {
 
flash1.begin ();
pinMode(flash2, OUTPUT);

   // end of setup
}

void loop() {
 
 delay(1000);
  digitalWrite(flash2, HIGH);
 delay(100);
 digitalWrite(flash2, LOW);
 delay(50);
 digitalWrite(flash2, HIGH);
 delay(100);
 digitalWrite(flash2, LOW);
 delay(1750);
 
 
 flash1.update ();
 
 
 }


The only advantage with the Nano is that you can run it of 12V and the ATtiny needs 5V.

I also use the same processor to run the Buzzards, each has 3 pairs of LEDs that are fired in sequence to replicate the rotation.  The advantage here is that with 3 pairs of LEDs you can swap the wires on the outer 2 LEDs and they rotate in the opposite direction.

 




Enterprise © Bloc