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] Starfleet Starship Running & Strobe Lights  (Read 9919 times)

Offline Gadgetron_3000

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

I recently got an Arduino Nano three-pack (http://scifimodelaction.com/sfmaforum/index.php?topic=232.msg64236#msg64236).





I chose to go with the Nano because of its size and price.  It's only 1.6875-inches (42.8625mm) x 0.625-inches (15.875mm), so it's small enough to fit almost anywhere.  The price was $10.95 U.S.D. for three with free shipping which comes out to $3.65 U.S.D. each.

Within a day, I was able to find out how to program the Nano to do some basic Starfleet starship running and strobe light effects.  I already have a stock of various LEDs, resistors, power supplies, power switches, magnet wire, solder, and USB cables, so why wouldn't I want to use those things and a $3.65 board that will do the exact same thing as something that would cost anywhere from $35.00 to $40.00 or greater?  And as a bonus, the Nano has so many pins (14 digital and 8 analog), that they can be reconfigured to be reused for anything else I might learn to do in the future (such as LED chasers, LED chaser wheels / rings, RGB and bi-color LED fading, etc.)

I wanted to start this thread for all us Arduino / coding newbies out there.  I'll make the steps as detailed as possible so that you can feel comfortable with doing things.  In the end, I think you'll be surprised how fast it is to program for and flash the Nano and to get things ready to go for your model kits.

:)
"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: 1124
Re: [How To - Arduino Nano] Starfleet Starship Running & Strobe Lights
« Reply #1 on: February 24, 2015, 04:41:49 pm »
First, you may need to get the device drivers for the Nano itself.  Since the Nano I bought is a Chinese-made one, it doesn't use the FTDI FT232RL serial communication chip to work over USB like original Arduino boards.  It uses a WCH CH340G chip for which you can get device drivers from:


Next, lets get things installed on your PC so that you can program that Nano.  There are versions of the open-source Arduino Software (IDE) for Windows, Mac OS X, and Linux.  Go to http://arduino.cc/en/Main/Software to get the version that is right for you.

NOTE: my PC is running Windows 8.1 64-bit so my instructions will reflect that.

1. Attach a USB cable with a male Mini-B USB connector to the the Nano's female port.



2. Plug the other end of the USB cable to your computer.  The USB port will power the Nano and Windows will begin trying to install drivers for the device.  If you need to manually install the device driver, do so from the set downloaded from the WCH website.  NOTE: on my Windows 8.1 machine, the drivers for the Nano automatically installed.



3. Download the Arduino Software (IDE) for Windows .EXE file from http://arduino.cc/download_handler.php?f=/arduino-1.6.0-windows.exe.
4. Run the .EXE file and follow the on-screen installation instructions.  NOTE: you don't need to install the Arduino Software bundled drivers if your WCH CH340G chip Nano is already confirmed to be properly detected and working in Windows.



5. Launch Arduino.exe.





6. Ensure that the correct board and COM port number (which is shown in Device Manager) has been selected.



And that's it!  Easy!
« Last Edit: March 23, 2015, 10:56:57 am by Gadgetron_3000 »
"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: 1124
Re: [How To - Arduino Nano] Starfleet Starship Running & Strobe Lights
« Reply #2 on: February 24, 2015, 04:47:17 pm »
Now onto programming the attached board.  Let's do the easiest one...TOS Starfleet Starship Running and Strobe Lights.  This Arduino sketch (the code itself) will have the Nano control four LEDs: two flashing running lights and two strobe lights.

This is intended for the Polar Lights / Round 2 1:1000 TOS Enterprise where the two running lights can be used in the primary hull and the two strobe lights can used in the secondary hull for the ion pods.

1. Copy the following code:
Quote
/*
  TOS Starfleet Starship Running & Strobe Lights:

    - Turns on two running lights LEDs on for 1.5 seconds (1500 milliseconds),
      then off for 0.5 second (500 milliseconds), repeatedly.

    - Turns on two strobe lights LEDs on for 0.5 second (500 milliseconds),
      then off for 0.5 second (500 milliseconds), repeatedly.
     
    - 1 second = 1000 milliseconds
   
    - TOS starship blink / flash rates researched by 'RossW'
      (http://www.hobbytalk.com/bbs1/showpost.php?p=4824675&postcount=15).

    - Based on original Arduino sketch by Jack Christensen
     (http://forum.arduino.cc/index.php?topic=220026.msg1607277#msg1607277).

  NOTE:

    - On the TOS Enterprise, the port-side running light is RED and
      the starboard-side running light is GREEN.

    - On the TOS Enterprise, the strobe lights are the 'ion pods'
      toward the rear of the secondary hull near the hangar bay doors.

*/

//LED pin numbers
const byte LED1 = 12;                           //running light LED 1
const byte LED2 = 10;                           //running light LED 2
const byte LED3 = 8;                            //strobe light LED 1
const byte LED4 = 6;                            //strobe light LED 2

void setup(void)
{
    pinMode(LED1, OUTPUT);                      //make each LED pin an output
    pinMode(LED2, OUTPUT);
    pinMode(LED3, OUTPUT);
    pinMode(LED4, OUTPUT);
}

void loop(void)
{
    runLED1();                                  //call the function for each LED 
    runLED2();
    runLED3();
    runLED4();
}

void runLED1(void)                              //**CHANGE the function name for each LED
{
    const unsigned long onTime = 1500;          //**CHANGE the on and off times for each LED
    const unsigned long offTime = 500;
    static unsigned long lastChangeTime;        //last time the LED was turned on or off
    static boolean state = true;                //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {    //on long enough?
            state = false;                      //yes, set state to off
            lastChangeTime = ms;                //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {   //off long enough?
            state = true;                       //yes, set state to on
            lastChangeTime = ms;                //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED1, state);                 //**CHANGE the pin argument for each LED
}

void runLED2(void)                             //**CHANGE the function name for each LED
{
    const unsigned long onTime = 1500;         //**CHANGE the on and off times for each LED
    const unsigned long offTime = 500;
    static unsigned long lastChangeTime;       //last time the LED was turned on or off
    static boolean state = true;               //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {   //on long enough?
            state = false;                     //yes, set state to off
            lastChangeTime = ms;               //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {  //off long enough?
            state = true;                      //yes, set state to on
            lastChangeTime = ms;               //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED2, state);                 //**CHANGE the pin argument for each LED
}

void runLED3(void)                             //**CHANGE the function name for each LED
{
    const unsigned long onTime = 500;          //**CHANGE the on and off times for each LED
    const unsigned long offTime = 500;
    static unsigned long lastChangeTime;       //last time the LED was turned on or off
    static boolean state = true;               //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {   //on long enough?
            state = false;                     //yes, set state to off
            lastChangeTime = ms;               //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {  //off long enough?
            state = true;                      //yes, set state to on
            lastChangeTime = ms;               //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED3, state);                 //**CHANGE the pin argument for each LED
}

void runLED4(void)                             //**CHANGE the function name for each LED
{
    const unsigned long onTime = 500;          //**CHANGE the on and off times for each LED
    const unsigned long offTime = 500;
    static unsigned long lastChangeTime;       //last time the LED was turned on or off
    static boolean state = true;               //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {   //on long enough?
            state = false;                     //yes, set state to off
            lastChangeTime = ms;               //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {  //off long enough?
            state = true;                      //yes, set state to on
            lastChangeTime = ms;               //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED4, state);                 //**CHANGE the pin argument for each LED
}

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!  Once again...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!  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.  You can also add more pin outputs to the code, if you want.

Check out the code in the Arduino software window to study it a bit.  There may be more efficient ways to code what is being done here, but the example I learned from went for a more straightforward and easy to understand approach.
« Last Edit: February 26, 2015, 12:00:54 pm by Gadgetron_3000 »
"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: 1124
Re: [How To - Arduino Nano] Starfleet Starship Running & Strobe Lights
« Reply #3 on: February 24, 2015, 04:50:29 pm »
Next lets reprogram the attached board to add two more running lights so that the Nano will control six LEDs: four flashing running lights and two strobe lights.

This is intended for the AMT / Round 2 1:650 TOS Enterprise where the four running lights can be used in the primary hull and the two strobe lights can used in the secondary hull for the ion pods.

1. Copy the following code:
Quote
/*
  TOS Starfleet Starship Running & Strobe Lights:

    - Turns on four running lights LEDs on for 1.5 seconds (1500 milliseconds),
      then off for 0.5 second (500 milliseconds), repeatedly.

    - Turns on two strobe lights LEDs on for 0.5 second (500 milliseconds),
      then off for 0.5 second (500 milliseconds), repeatedly.
     
    - 1 second = 1000 milliseconds
   
    - TOS starship blink / flash rates researched by 'RossW'
      (http://www.hobbytalk.com/bbs1/showpost.php?p=4824675&postcount=15).

    - Based on original Arduino sketch by Jack Christensen
     (http://forum.arduino.cc/index.php?topic=220026.msg1607277#msg1607277).

  NOTE:

    - On the TOS Enterprise, the port-side running light is RED and
      the starboard-side running light is GREEN.

    - On the TOS Enterprise, the strobe lights are the 'ion pods'
      toward the rear of the secondary hull near the hangar bay doors.

*/

//LED pin numbers
const byte LED1 = 12;                           //running light LED 1
const byte LED2 = 11;                           //running light LED 2
const byte LED3 = 10;                           //running light LED 3
const byte LED4 = 9;                            //running light LED 4
const byte LED5 = 8;                            //strobe light LED 1
const byte LED6 = 6;                            //strobe light LED 2

void setup(void)
{
    pinMode(LED1, OUTPUT);                      //make each LED pin an output
    pinMode(LED2, OUTPUT);
    pinMode(LED3, OUTPUT);
    pinMode(LED4, OUTPUT);
    pinMode(LED5, OUTPUT);
    pinMode(LED6, OUTPUT);
}

void loop(void)
{
    runLED1();                                  //call the function for each LED 
    runLED2();
    runLED3();
    runLED4();
    runLED5();
    runLED6();
}

void runLED1(void)                              //**CHANGE the function name for each LED
{
    const unsigned long onTime = 1500;          //**CHANGE the on and off times for each LED
    const unsigned long offTime = 500;
    static unsigned long lastChangeTime;        //last time the LED was turned on or off
    static boolean state = true;                //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {    //on long enough?
            state = false;                      //yes, set state to off
            lastChangeTime = ms;                //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {   //off long enough?
            state = true;                       //yes, set state to on
            lastChangeTime = ms;                //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED1, state);                 //**CHANGE the pin argument for each LED
}

void runLED2(void)                             //**CHANGE the function name for each LED
{
    const unsigned long onTime = 1500;         //**CHANGE the on and off times for each LED
    const unsigned long offTime = 500;
    static unsigned long lastChangeTime;       //last time the LED was turned on or off
    static boolean state = true;               //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {   //on long enough?
            state = false;                     //yes, set state to off
            lastChangeTime = ms;               //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {  //off long enough?
            state = true;                      //yes, set state to on
            lastChangeTime = ms;               //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED2, state);                 //**CHANGE the pin argument for each LED
}

void runLED3(void)                             //**CHANGE the function name for each LED
{
    const unsigned long onTime = 1500;         //**CHANGE the on and off times for each LED
    const unsigned long offTime = 500;
    static unsigned long lastChangeTime;       //last time the LED was turned on or off
    static boolean state = true;               //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {   //on long enough?
            state = false;                     //yes, set state to off
            lastChangeTime = ms;               //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {  //off long enough?
            state = true;                      //yes, set state to on
            lastChangeTime = ms;               //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED3, state);                 //**CHANGE the pin argument for each LED
}

void runLED4(void)                             //**CHANGE the function name for each LED
{
    const unsigned long onTime = 1500;         //**CHANGE the on and off times for each LED
    const unsigned long offTime = 500;
    static unsigned long lastChangeTime;       //last time the LED was turned on or off
    static boolean state = true;               //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {   //on long enough?
            state = false;                     //yes, set state to off
            lastChangeTime = ms;               //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {  //off long enough?
            state = true;                      //yes, set state to on
            lastChangeTime = ms;               //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED4, state);                 //**CHANGE the pin argument for each LED
}

void runLED5(void)                             //**CHANGE the function name for each LED
{
    const unsigned long onTime = 500;          //**CHANGE the on and off times for each LED
    const unsigned long offTime = 500;
    static unsigned long lastChangeTime;       //last time the LED was turned on or off
    static boolean state = true;               //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {   //on long enough?
            state = false;                     //yes, set state to off
            lastChangeTime = ms;               //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {  //off long enough?
            state = true;                      //yes, set state to on
            lastChangeTime = ms;               //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED5, state);                 //**CHANGE the pin argument for each LED
}

void runLED6(void)                             //**CHANGE the function name for each LED
{
    const unsigned long onTime = 500;          //**CHANGE the on and off times for each LED
    const unsigned long offTime = 500;
    static unsigned long lastChangeTime;       //last time the LED was turned on or off
    static boolean state = true;               //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {   //on long enough?
            state = false;                     //yes, set state to off
            lastChangeTime = ms;               //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {  //off long enough?
            state = true;                      //yes, set state to on
            lastChangeTime = ms;               //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED6, state);                 //**CHANGE the pin argument for each LED
}

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!  Once again...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!  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.  You can also add more pin outputs to the code, if you want.

Check out the code in the Arduino software window to study it a bit.  There may be more efficient ways to code what is being done here, but again the example I learned from went for a more straightforward and easy to understand approach.
« Last Edit: February 26, 2015, 12:01:22 pm by Gadgetron_3000 »
"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: 1124
Re: [How To - Arduino Nano] Starfleet Starship Running & Strobe Lights
« Reply #4 on: February 24, 2015, 04:53:16 pm »
For this third example, let's go from TOS to TMP...TMP Starfleet Starship Running and Strobe Lights.  This Arduino sketch will have the Nano control twelve LEDs: eight flashing running lights and four strobe lights.

This is intended for the AMT / ERTL 1:537 Enterprise Refit, the Polar Lights / Round 2 1:350 Enterprise Refit, and the Polar Lights / Round 2 1:1000 Enterprise Refit where the eight running lights can be used in the primary hull and the four strobe lights can used in the back of the bridge, the bottom of the secondary hull, and in the rear of the warp nacelles.

1. Copy the following code:
Quote
/*
  TMP Starfleet Starship Running & Strobe Lights:

    - Turns on eight running lights LEDs on for 1.083 seconds (1083 milliseconds),
      then off for 1.083 seconds (1083 milliseconds), repeatedly.

    - Turns on four strobe lights LEDs on for 0.0417 second (41.7 milliseconds),
      then off for 0.75 second (750 milliseconds), repeatedly.
     
    - 1 second = 1000 milliseconds
   
    - TMP starship blink / flash rates researched by 'Marc111'
      (http://www.showcase.netins.net/web/marc111creations/PL_Enterprise_Refit_WIP_1.htm).

    - Based on original Arduino sketch by Jack Christensen
      (http://forum.arduino.cc/index.php?topic=220026.msg1607277#msg1607277).

  NOTE:

    - On the Refit Enterprise, the port-side running lights are RED, the
      starboard-side running lights are GREEN, and the bow running lights
      are WHITE.

*/

//LED pin numbers
const byte LED1 = 12;                           //running light LED 1
const byte LED2 = 11;                           //running light LED 2
const byte LED3 = 10;                           //running light LED 3
const byte LED4 = 9;                            //running light LED 4
const byte LED5 = 8;                            //running light LED 5
const byte LED6 = 7;                            //running light LED 6
const byte LED7 = 6;                            //running light LED 7
const byte LED8 = 5;                            //running light LED 8
const byte LED9 = 4;                            //strobe light LED 1
const byte LED10 = 3;                           //strobe light LED 2
const byte LED11 = 2;                           //strobe light LED 3
const byte LED12 = 13;                          //strobe light LED 4

void setup(void)
{
    pinMode(LED1, OUTPUT);                      //make each LED pin an output
    pinMode(LED2, OUTPUT);
    pinMode(LED3, OUTPUT);
    pinMode(LED4, OUTPUT);
    pinMode(LED5, OUTPUT);
    pinMode(LED6, OUTPUT);
    pinMode(LED7, OUTPUT);
    pinMode(LED8, OUTPUT);
    pinMode(LED9, OUTPUT);
    pinMode(LED10, OUTPUT);
    pinMode(LED11, OUTPUT);
    pinMode(LED12, OUTPUT);

}

void loop(void)
{
    runLED1();                                  //call the function for each LED 
    runLED2();
    runLED3();
    runLED4();
    runLED5();
    runLED6();
    runLED7();
    runLED8();
    runLED9();
    runLED10();
    runLED11();
    runLED12();
}

void runLED1(void)                              //**CHANGE the function name for each LED
{
    const unsigned long onTime = 1083;          //**CHANGE the on and off times for each LED
    const unsigned long offTime = 1083;
    static unsigned long lastChangeTime;        //last time the LED was turned on or off
    static boolean state = true;                //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {    //on long enough?
            state = false;                      //yes, set state to off
            lastChangeTime = ms;                //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {   //off long enough?
            state = true;                       //yes, set state to on
            lastChangeTime = ms;                //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED1, state);                  //**CHANGE the pin argument for each LED
}

void runLED2(void)                              //**CHANGE the function name for each LED
{
    const unsigned long onTime = 1083;          //**CHANGE the on and off times for each LED
    const unsigned long offTime = 1083;
    static unsigned long lastChangeTime;        //last time the LED was turned on or off
    static boolean state = true;                //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {    //on long enough?
            state = false;                      //yes, set state to off
            lastChangeTime = ms;                //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {   //off long enough?
            state = true;                       //yes, set state to on
            lastChangeTime = ms;                //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED2, state);                  //**CHANGE the pin argument for each LED
}

void runLED3(void)                              //**CHANGE the function name for each LED
{
    const unsigned long onTime = 1083;          //**CHANGE the on and off times for each LED
    const unsigned long offTime = 1083;
    static unsigned long lastChangeTime;        //last time the LED was turned on or off
    static boolean state = true;                //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {    //on long enough?
            state = false;                      //yes, set state to off
            lastChangeTime = ms;                //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {   //off long enough?
            state = true;                       //yes, set state to on
            lastChangeTime = ms;                //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED3, state);                  //**CHANGE the pin argument for each LED
}

void runLED4(void)                              //**CHANGE the function name for each LED
{
    const unsigned long onTime = 1083;          //**CHANGE the on and off times for each LED
    const unsigned long offTime = 1083;
    static unsigned long lastChangeTime;        //last time the LED was turned on or off
    static boolean state = true;                //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {    //on long enough?
            state = false;                      //yes, set state to off
            lastChangeTime = ms;                //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {   //off long enough?
            state = true;                       //yes, set state to on
            lastChangeTime = ms;                //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED4, state);                  //**CHANGE the pin argument for each LED
}

void runLED5(void)                              //**CHANGE the function name for each LED
{
    const unsigned long onTime = 1083;          //**CHANGE the on and off times for each LED
    const unsigned long offTime = 1083;
    static unsigned long lastChangeTime;        //last time the LED was turned on or off
    static boolean state = true;                //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {    //on long enough?
            state = false;                      //yes, set state to off
            lastChangeTime = ms;                //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {   //off long enough?
            state = true;                       //yes, set state to on
            lastChangeTime = ms;                //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED5, state);                  //**CHANGE the pin argument for each LED
}

void runLED6(void)                              //**CHANGE the function name for each LED
{
    const unsigned long onTime = 1083;          //**CHANGE the on and off times for each LED
    const unsigned long offTime = 1083;
    static unsigned long lastChangeTime;        //last time the LED was turned on or off
    static boolean state = true;                //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {    //on long enough?
            state = false;                      //yes, set state to off
            lastChangeTime = ms;                //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {   //off long enough?
            state = true;                       //yes, set state to on
            lastChangeTime = ms;                //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED6, state);                  //**CHANGE the pin argument for each LED
}

void runLED7(void)                              //**CHANGE the function name for each LED
{
    const unsigned long onTime = 1083;          //**CHANGE the on and off times for each LED
    const unsigned long offTime = 1083;
    static unsigned long lastChangeTime;        //last time the LED was turned on or off
    static boolean state = true;                //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {    //on long enough?
            state = false;                      //yes, set state to off
            lastChangeTime = ms;                //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {   //off long enough?
            state = true;                       //yes, set state to on
            lastChangeTime = ms;                //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED7, state);                  //**CHANGE the pin argument for each LED
}

void runLED8(void)                              //**CHANGE the function name for each LED
{
    const unsigned long onTime = 1083;          //**CHANGE the on and off times for each LED
    const unsigned long offTime = 1083;
    static unsigned long lastChangeTime;        //last time the LED was turned on or off
    static boolean state = true;                //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {    //on long enough?
            state = false;                      //yes, set state to off
            lastChangeTime = ms;                //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {   //off long enough?
            state = true;                       //yes, set state to on
            lastChangeTime = ms;                //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED8, state);                 //**CHANGE the pin argument for each LED
}

void runLED9(void)                             //**CHANGE the function name for each LED
{
    const unsigned long onTime = 41.7;         //**CHANGE the on and off times for each LED
    const unsigned long offTime = 750;
    static unsigned long lastChangeTime;       //last time the LED was turned on or off
    static boolean state = true;               //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {   //on long enough?
            state = false;                     //yes, set state to off
            lastChangeTime = ms;               //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {  //off long enough?
            state = true;                      //yes, set state to on
            lastChangeTime = ms;               //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED9, state);                 //**CHANGE the pin argument for each LED
}

void runLED10(void)                            //**CHANGE the function name for each LED
{
    const unsigned long onTime = 41.7;         //**CHANGE the on and off times for each LED
    const unsigned long offTime = 750;
    static unsigned long lastChangeTime;       //last time the LED was turned on or off
    static boolean state = true;               //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {   //on long enough?
            state = false;                     //yes, set state to off
            lastChangeTime = ms;               //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {  //off long enough?
            state = true;                      //yes, set state to on
            lastChangeTime = ms;               //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED10, state);                //**CHANGE the pin argument for each LED
}

void runLED11(void)                            //**CHANGE the function name for each LED
{
    const unsigned long onTime = 41.7;         //**CHANGE the on and off times for each LED
    const unsigned long offTime = 750;
    static unsigned long lastChangeTime;       //last time the LED was turned on or off
    static boolean state = true;               //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {   //on long enough?
            state = false;                     //yes, set state to off
            lastChangeTime = ms;               //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {  //off long enough?
            state = true;                      //yes, set state to on
            lastChangeTime = ms;               //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED11, state);                //**CHANGE the pin argument for each LED
}

void runLED12(void)                            //**CHANGE the function name for each LED
{
    const unsigned long onTime = 41.7;         //**CHANGE the on and off times for each LED
    const unsigned long offTime = 750;
    static unsigned long lastChangeTime;       //last time the LED was turned on or off
    static boolean state = true;               //current LED state, true=on, false=off. start on
   
    unsigned long ms = millis();
    if (state) {    //LED on?
        if (ms - lastChangeTime >= onTime) {   //on long enough?
            state = false;                     //yes, set state to off
            lastChangeTime = ms;               //and record the time
        }
    }
    else { //LED is off
        if (ms - lastChangeTime >= offTime) {  //off long enough?
            state = true;                      //yes, set state to on
            lastChangeTime = ms;               //and record the time
        }
    }
    //set the LED's state
    digitalWrite(LED12, state);                //**CHANGE the pin argument for each LED
}

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!  Once again...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!  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.  You can also add more pin outputs to the code, if you want.

Check out the code in the Arduino software window to study it a bit.  There may be more efficient ways to code what is being done here, but again the example I learned from went for a more straightforward and easy to understand approach.
« Last Edit: February 26, 2015, 12:02:01 pm by Gadgetron_3000 »
"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: 1124
Re: [How To - Arduino Nano] Starfleet Starship Running & Strobe Lights
« Reply #5 on: February 24, 2015, 04:58:08 pm »
As I learn more and add more lighting effects for the Nano to control, I will start new forum threads for whatever the topic will be.

I hope you found this one useful.

Have fun, Everyone!

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

-----

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

Offline MarkW

  • Plastic Surgeon
  • Admiral
  • *****
  • Posts: 1329
    • MW ModelWerks
Re: [How To - Arduino Nano] Starfleet Starship Running & Strobe Lights
« Reply #6 on: February 24, 2015, 06:46:28 pm »
First, these are great examples with the real world application. That is something that is too often lacking in many of the Arduino tutorials.

Have you tried running the fourth example for a very long time?  I'm curious if they would ever end up getting out of sync. Granted at the speed at which the processor runs, it shouldn't be an issue.

 An alternative approach to having each LED controlled by one pin on the Arduino, which pulls a lot of current through the Arduino, would be to have all eight of the LEDs running off of one pin on the Arduino, and connected with a transistor to a string of LEDs. Otherwise you will soon run out of available current and pins if you try to just do one LED at a time per pin .
MarkW
"I can cross stab Hitler to death off the list of cool crap I thought I'd never do"
--Brock Sampson
NEW WEB ADDRESS

Offline Armandodlc

  • Global Moderator
  • Admiral
  • *****
  • Posts: 1857
  • I am the beginning. The end. The one who is many.
    • DLC Model Builders on Google +
Re: [How To - Arduino Nano] Starfleet Starship Running & Strobe Lights
« Reply #7 on: February 24, 2015, 06:52:02 pm »
Fantastic...gonna run out and get me these boards now and give this all a try.
My youtube channel: DLC Model Builders is at http://www.youtube.com/channel/UCCmRSBxKoouCslj6_-bOPcQ

Offline Tankton

  • Admiral
  • *****
  • Posts: 1941
Re: [How To - Arduino Nano] Starfleet Starship Running & Strobe Lights
« Reply #8 on: February 24, 2015, 06:56:17 pm »
Just uploaded the last one to a Pro Mini will see how it works on the breadboard. Will let you know.

added the mini pinout to your pic looks the same.
Live Long and Prosper

Cameron Lewis Sr.

Online simi

  • Admiral
  • *****
  • Posts: 583
  • JUST enough knowledge to do some serious damage
Re: [How To - Arduino Nano] Starfleet Starship Running & Strobe Lights
« Reply #9 on: February 24, 2015, 08:04:07 pm »
Awesome info.  Just as an FYI (this is for people like me...) you can get the Arduino clones with the header pins already soldered on if that's your preference (link below).  These things are dirt cheap and not too terribly difficult to program.  And if programming isn't your thing - you can use your google-foo to find existing sample code (like all the great stuff Gadgetron provided) to get you 80% to your destination.

http://www.ebay.com/itm/Mini-USB-Nano-V3-0-ATmega328P-5V-16M-Micro-controller-Board-For-Arduino-1pcs-/171488914920?pt=LH_DefaultDomain_0&hash=item27ed892de8
As a software architect, I'm pretty darn good.  As someone with knowledge of building things in the real world, well, I'm a software architect.

Offline Gadgetron_3000

  • Admiral
  • *****
  • Posts: 1124
Re: [How To - Arduino Nano] Starfleet Starship Running & Strobe Lights
« Reply #10 on: February 26, 2015, 12:21:01 pm »
Have you tried running the fourth example for a very long time?  I'm curious if they would ever end up getting out of sync. Granted at the speed at which the processor runs, it shouldn't be an issue.

I've run tests with the third example (TMP Starfleet Starship Running & Strobe Lights) for over an hour and did not experience any kind of sync issue.

Quote
An alternative approach to having each LED controlled by one pin on the Arduino, which pulls a lot of current through the Arduino, would be to have all eight of the LEDs running off of one pin on the Arduino, and connected with a transistor to a string of LEDs. Otherwise you will soon run out of available current and pins if you try to just do one LED at a time per pin .

Each of the Nano's digital pins can output 5-volts with up to 40mA of current.  That is more than enough to run single LEDs attached to each pin.  The setups I created for this thread are simplistic, but I wanted them to be purposely so.  This way, someone can just throw the Nano (or other compatible Arduino device) into his/her mix of already-stocked electronic parts and almost instantly have a basic, decent control board.

In the near future, I will be ordering some 2N5551 NPN transistors to create a different setup where the LEDs aren't powered by the Nano and where I can have multiple LEDs controlled by single pins.  In the end, that should be more efficient...especially as I hopefully learn other effects that can be programmed into the Nano to make it part of a more complete lighting solution.

:)
"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: 1124
Re: [How To - Arduino Nano] Starfleet Starship Running & Strobe Lights
« Reply #11 on: February 26, 2015, 12:34:14 pm »
Fantastic...gonna run out and get me these boards now and give this all a try.

Give it a try.  I think you would be pleasantly surprised with the results.

I will eventually post new threads with new effects that can be used in many different ways.


Just uploaded the last one to a Pro Mini will see how it works on the breadboard. Will let you know.

added the mini pinout to your pic looks the same.

How did it work out with your Mini Pro?

I just recently saw the Mini Pro on eBay, and I couldn't believe that it was even smaller than the Nano.  I know this is because the USB component is separate on the Mini Pro to allow for its shorter length.  But I guess I'll stick with the Nano since it's still a good best-bang-for-the-buck board.


Awesome info.  Just as an FYI (this is for people like me...) you can get the Arduino clones with the header pins already soldered on if that's your preference (link below).  These things are dirt cheap and not too terribly difficult to program.  And if programming isn't your thing - you can use your google-foo to find existing sample code (like all the great stuff Gadgetron provided) to get you 80% to your destination.

Yep, the Chinese-made Arduinos can be had for so little and they work just fine.  I'm actually about to order a bunch more of the Nanos.  So many model kits can benefit from them!

:)
"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: 1124
Re: [How To - Arduino Nano] Starfleet Starship Running & Strobe Lights
« Reply #12 on: February 26, 2015, 01:04:54 pm »
I posted a demo of the TMP Starfleet Starships Running & Strobe Lights test setup on YouTube...

http://youtu.be/hzdCkOwSJkc





:)
« Last Edit: February 26, 2015, 01:42:55 pm by Gadgetron_3000 »
"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: 1124
Re: [How To - Arduino Nano] Starfleet Starship Running & Strobe Lights
« Reply #13 on: February 26, 2015, 02:28:48 pm »
I also posted a demo of the TOS Starfleet Starships Running & Strobe Lights test setup on YouTube...

http://youtu.be/pbFnVqfHq2M



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

-----

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

Offline TK Iain

  • Admiral
  • *****
  • Posts: 1831
Re: [How To - Arduino Nano] Starfleet Starship Running & Strobe Lights
« Reply #14 on: February 26, 2015, 02:52:54 pm »
I was with you right up to when you said "Hi Everyone". :-[ Then my brain went fart!


Still - nothing ventured, nothing gained so I have bought one of these boards to try it out. ;)

Who knows if I can suss this out I will use it on my 1701E build.
« Last Edit: February 26, 2015, 03:13:21 pm by TK Iain »
Iain

 




Enterprise © Bloc