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 Fading Lights  (Read 167 times)

Offline Gadgetron_3000

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

Here is another Arduino sketch.  This time for TOS Starfleet Starship Bussard Fader Lights.

First, if you need to 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 randomly fades on between 0 to 1.5 seconds and each has a random brightness intensity between 0 (off) to 255 (full).

The code allows one to reduce or add to the number of LEDs (depending on the available number of PWM pins on the Arduino being used) and to change the fade time and brightness intensity ranges of each.

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/q3QGRZWQGAY.

Now onto programming the attached board...

IMPORTANT: For this code, you will need a LEDFader.h library.  The download and instructions can be found here: https://github.com/jgillick/arduino-LEDFader.  Unzip and rename the LEDFader.h library folder and files according to the instructions into the C:\Users\<Windows user name>\Documents\Arduino\libraries folder.

1. Copy the following code:

Quote
/*

  5 LED Random Intensity and Time Fader:

    - Fades six LEDs to random intensities (between 0 to 255) at random
      durations (between 0 to 1.5 seconds).

    - Must be used with PWM pins only. 

    - 1000 milliseconds = 1 second

    - The LEDFader.h library will be needed.  The download and instructions can be found
      here: https://github.com/jgillick/arduino-LEDFader.

    - Based on original Arduino sketch by Jeremy Gillick
      (http://mozmonkey.com/2013/10/arduino-fade-leds-without-blocking/).

*/

#include <LEDFader.h>              // Don't forget to include the LEDFader libraries folder in the libraries folder
 
#define LED_NUM 5                  // Number of LEDs
 
// 5 LED pin setup
LEDFader leds[LED_NUM] = {
  LEDFader(3),                     // PWM pin
  LEDFader(5),                     // PWM pin
  LEDFader(6),                     // PWM pin
  LEDFader(9),                     // PWM pin
  LEDFader(11)                     // PWM pin
};
 
void setup() {
}
 
void loop() {
 
  // Update all LEDs and start new fades if any are done
  for (byte i = 0; i < LED_NUM; i++) {
    LEDFader *led = &leds;
    led->update();
 
    // This LED is not fading, start a new fade
    if (led->is_fading() == false) {
      int duration = random(0, 1500);                // Duration between 0 to 1.5 seconds
 
      // Fade Up
      if (led->get_value() == 0) {
        byte intensity = random(0, 255);             // Brightness intensity between 0 (off) to 255 (maximum)
        led->fade(intensity, duration);
      }
      // Fade Down
      else {
        led->fade(0, duration);
      }
    }
  }
}

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.

:)
« Last Edit: April 29, 2017, 10:13:31 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 Tankton

  • Admiral
  • *****
  • Posts: 1892
Re: [How To - Arduino Nano] TOS Starfleet Starship Bussard Fading Lights
« Reply #1 on: April 29, 2017, 03:15:43 pm »
Thanks.
Live Long and Prosper

Cameron Lewis Sr.

Offline texastony1946

  • Ensign
  • *
  • Posts: 18
Re: [How To - Arduino Nano] TOS Starfleet Starship Bussard Fading Lights
« Reply #2 on: April 30, 2017, 09:02:51 am »
Thanks for the code. I'll probably use this in an upcoming build.

Offline RossW

  • Commander
  • ***
  • Posts: 225
Re: [How To - Arduino Nano] TOS Starfleet Starship Bussard Fading Lights
« Reply #3 on: April 30, 2017, 09:30:48 am »
Bloody brilliant! I've been working on my own TOS E blinking bussard light solution for years using a PIC microchip, but the fading is no where near as smooth as yours. Well done.

Offline RossW

  • Commander
  • ***
  • Posts: 225
Re: [How To - Arduino Nano] TOS Starfleet Starship Bussard Fading Lights
« Reply #4 on: April 30, 2017, 09:44:00 am »
I'm getting a compile error with the code and UNO board:

Quote
Arduino: 1.6.5 (Mac OS X), Board: "Arduino Uno"

Build options changed, rebuilding all
Using library LEDFader in folder: /Users/rwaddell/Dropbox/Arduino Projects/libraries/LEDFader (legacy)

/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10605 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino -I/Applications/Arduino.app/Contents/Java/hardware/arduino/avr/variants/standard -I/Users/rwaddell/Dropbox/Arduino Projects/libraries/LEDFader /var/folders/nb/2356s9gj6y714v9fzf4hck080000gn/T/build7300695285594820882.tmp/TOS_E_Blinking_Warp_Engine_Lights.cpp -o /var/folders/nb/2356s9gj6y714v9fzf4hck080000gn/T/build7300695285594820882.tmp/TOS_E_Blinking_Warp_Engine_Lights.cpp.o
TOS_E_Blinking_Warp_Engine_Lights.ino: In function 'void loop()':
TOS_E_Blinking_Warp_Engine_Lights.ino:40:22: error: cannot convert 'LEDFader (*)[5]' to 'LEDFader*' in initialization
cannot convert 'LEDFader (*)[5]' to 'LEDFader*' in initialization

The examples from LEDFader compile just fine, so I think it's something specific to this code:

Code: [Select]
LEDFader *led = &leds;
« Last Edit: April 30, 2017, 09:48:04 am by RossW »

Offline RossW

  • Commander
  • ***
  • Posts: 225
Re: [How To - Arduino Nano] TOS Starfleet Starship Bussard Fading Lights
« Reply #5 on: April 30, 2017, 09:52:09 am »
Looks like the code in question should be this:

Code: [Select]
LEDFader *led = &leds[i];
It now compiles fine.
« Last Edit: May 04, 2017, 12:37:42 pm by RossW »

Offline Gadgetron_3000

  • Admiral
  • *****
  • Posts: 1093
It now compiles fine.

Glad it's working for you now.

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

-----

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

 




Enterprise © Bloc