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 508 times)

Offline Gadgetron_3000

  • Admiral
  • *****
  • Posts: 1124
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: 1941
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: 20
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: 234
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: 234
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: 234
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: 1124
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

Offline rmpitzer

  • Ensign
  • *
  • Posts: 12
Thanks Gadget and Ross!  Giving it a try tonight. :)


Offline RossW

  • Commander
  • ***
  • Posts: 234
Thanks Gadget and Ross!  Giving it a try tonight. :)
You'll love it! I'm using it in my Arduino demo at WonderFest this weekend, along with a few other sketches.

Offline RossW

  • Commander
  • ***
  • Posts: 234
Re: [How To - Arduino Nano] TOS Starfleet Starship Bussard Fading Lights
« Reply #9 on: June 25, 2017, 11:48:57 am »
Got my custom PCBs back from my board maker and soldered everything up and whadayknow - it works! I just need to tweak the brightness of the flashing coloured LEDs so they don't wash out the pulsing amber LEDs, and maybe play with some of the timings, but I think this is what I'm going to go with.

https://youtu.be/WqgfRiNmm2A

I'm using all 6 PWM pins on my Arduino Pro Mini - 5 for the flashing coloured LEDs (connected to 15 LEDs, some 2mm, some SMDs) and one for the pulsing 5 amber LEDs.

Here's the code:

Quote
/*

  Board -> Ardunio Pro or Pro Mini
  Processor -> ATmega328 (5V, 16Mhz)
  Port -> (whichever one has "usb" in it; board needs to be connected)
  Programmer -> AVRISP mkII


http://scifimodelaction.com/sfmaforum/index.php?topic=6850.msg88253#msg88253

  5 LED Random Intensity and Time Fader:

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

    - Pulses five amber LEDs connected to the same pin

    - 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

#define LED_NUM 5                  // Number of flashing coloured LED pins

// 5 pin blinking LED setup
LEDFader leds[LED_NUM] = {
  LEDFader(3),                     // PWM pin
  LEDFader(5),                     // PWM pin
  LEDFader(6),                     // PWM pin
  LEDFader(9),                     // PWM pin
  LEDFader(10),                    // PWM pin
};

#define AMBER_LED_PIN 11           // Amber LEDs (5 in pentagon shape)
#define FADE_UP_TIME 1500          // Time to power up
#define PULSE_TIME 500             // Fade down/up pulse time
#define MAX_BRIGHTNESS 225         // Max brightness of LEDs
#define MIN_BRIGHTNESS 170         // Min brightness of LEDs to fade to (pulse)
#define DIR_UP 1
#define DIR_DOWN -1

LEDFader amber_led;
int direction = DIR_UP;


void setup() {
  randomSeed(analogRead(0));

  amber_led = LEDFader(AMBER_LED_PIN);
  amber_led.fade(MAX_BRIGHTNESS, FADE_UP_TIME);
}
 
void loop() {

  // Pulsing amber LEDs
  // ==================

  amber_led.update();

  // LED no longer fading, switch direction
  if (!amber_led.is_fading()) {

    // Fade down
    if (direction == DIR_UP) {
      amber_led.fade(MIN_BRIGHTNESS, PULSE_TIME);
      direction = DIR_DOWN;
    }
    // Fade up
    else {
      amber_led.fade(MAX_BRIGHTNESS, PULSE_TIME);
      direction = DIR_UP;
    }
  }


  // Blinking coloured LEDs
  // ======================
 
// try LEDFader's faster and slower methods:

// Increase the current fading speed by a number of milliseconds
//    void faster(int by_seconds);

// Decrease the current fading speed by a number of milliseconds
//    void slower(int by_seconds);

  // 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(125, 500);             // Duration between 100 to 750 ms (0.75 s)
      // int duration = random(100, 750);
      // int duration = random(0, 750);
      // int duration = random(1000, 3000);
 
      // Fade Up
      if (led->get_value() == 0) {
        byte intensity = random(75, 150);           // Brightness intensity between 0 (off) to 255 (maximum)
        // byte intensity = random(15, 50);
        // byte intensity = random(0,75);
        // byte intensity = random(100, 255);

        led->fade(intensity, duration);
      }
      // Fade Down
      else {
        led->fade(0, duration);
      }
    }
  }
}

Offline rmpitzer

  • Ensign
  • *
  • Posts: 12
Re: [How To - Arduino Nano] TOS Starfleet Starship Bussard Fading Lights
« Reply #10 on: July 12, 2017, 01:17:31 pm »
NICE!  That board looks sweet.....you should sell those (hint hint) ;)


Offline RossW

  • Commander
  • ***
  • Posts: 234
Re: [How To - Arduino Nano] TOS Starfleet Starship Bussard Fading Lights
« Reply #11 on: July 12, 2017, 01:39:49 pm »
NICE!  That board looks sweet.....you should sell those (hint hint) ;)
Thanks!

 




Enterprise © Bloc