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] TOS Starfleet Starship Bussard Blinking Lights  (Read 267 times)

Offline Gadgetron_3000

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

Here is another Arduino sketch.  This time for TOS Starfleet Starship Bussard Blinking 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.

This Arduino sketch will have the Nano control five LEDs.  Each one turns on randomly and each has a random blink time range between 0.25 second and 1.5 seconds.  The code allows one to reduce or add to the number of LEDs and to change the time range for each LED.  It's easy to have it handle two Bussard assemblies.

This is intended for any TOS-era starship.  However, it can also be used for things such as cockpit interior lights, robot lights, equipment lights, etc..  I posted a demo video on YouTube: https://youtu.be/cEF-JAG8nUg.

Now onto programming the attached board...

1. Copy the following code:

Quote
/*
  5 LED Random-Time-Range Flasher:

    - Turns on five LEDs between random time ranges (0.25 second to 1.5 seconds).

    - 1000 milliseconds = 1 second

    - Based on original Arduino sketch by 'kslagerman'
      (http://forum.arduino.cc/index.php?topic=143187.msg1075489#msg1075489).

*/

int led1Pin = 12;
int led2Pin = 10;
int led3Pin = 8;
int led4Pin = 6;
int led5Pin = 4;
int led1State = LOW;
int led2State = LOW;
int led3State = LOW;
int led4State = LOW;
int led5State = LOW;
long previousMillis1 = 0;
long previousMillis2 = 0;
long previousMillis3 = 0;
long previousMillis4 = 0;
long previousMillis5 = 0;
long randInterval1 = 0;
long randInterval2 = 0;
long randInterval3 = 0;
long randInterval4 = 0;
long randInterval5 = 0;

void setup()
{
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  pinMode(led3Pin, OUTPUT);
  pinMode(led4Pin, OUTPUT);
  pinMode(led5Pin, OUTPUT);
  randomSeed (analogRead (0));
}

void loop()
{

  unsigned long currentMillis = millis();

  //LED 1/////////////////////////
  if(currentMillis - previousMillis1 > randInterval1) {
    randInterval1 = random (250, 1500);                   //**CHANGE the random time range here in milliseconds - default is 250 milliseconds (0.25 second) to 1500 milliseconds (1.5 seconds)
    previousMillis1 = currentMillis;

    if (led1State == LOW)
      led1State = HIGH;
    else
      led1State = LOW;

    digitalWrite(led1Pin, led1State);
  }

  //LED 2/////////////////////////
  if(currentMillis - previousMillis2 > randInterval2) {
    randInterval2 = random (250, 1500);                   //**CHANGE the random time range here in milliseconds - default is 250 milliseconds (0.25 second) to 1500 milliseconds (1.5 seconds)
    previousMillis2 = currentMillis;

    if (led2State == LOW)
      led2State = HIGH;
    else
      led2State = LOW;

    digitalWrite(led2Pin, led2State);
  }

  //LED 3/////////////////////////
  if(currentMillis - previousMillis3 > randInterval3) {
    randInterval3 = random (250, 1500);                   //**CHANGE the random time range here in milliseconds - default is 250 milliseconds (0.25 second) to 1500 milliseconds (1.5 seconds)
    previousMillis3 = currentMillis;

    if (led3State == LOW)
      led3State = HIGH;
    else
      led3State = LOW;

    digitalWrite(led3Pin, led3State);
  }

  //LED 4/////////////////////////
  if(currentMillis - previousMillis4 > randInterval4) {
    randInterval4 = random (250, 1500);                   //**CHANGE the random time range here in milliseconds - default is 250 milliseconds (0.25 second) to 1500 milliseconds (1.5 seconds)
    previousMillis4 = currentMillis;

    if (led4State == LOW)
      led4State = HIGH;
    else
      led4State = LOW;

    digitalWrite(led4Pin, led4State);
  }
 
  //LED 5/////////////////////////
  if(currentMillis - previousMillis5 > randInterval5) {
    randInterval5 = random (250, 1500);                   //**CHANGE the random time range here in milliseconds - default is 250 milliseconds (0.25 second) to 1500 milliseconds (1.5 seconds)
    previousMillis5 = currentMillis;

    if (led5State == LOW)
      led5State = HIGH;
    else
      led5State = LOW;

    digitalWrite(led5Pin, led5State);
  }

}

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 setup!  You should be able to use a 9- or 12-volt power supply.  For the purposes of my testing, I used a 5-volt "power bank" external rechargeable battery.

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

-----

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

Offline Tankton

  • Admiral
  • *****
  • Posts: 1984
Thanks Gadget been looking for something like this.
Live Long and Prosper

Cameron Lewis Sr.

Offline shrapnel2389

  • Lieutenant
  • **
  • Posts: 79
great work, can't wait to put it to use.

 




Enterprise © Bloc