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

Login with username, password and session length
 

Author Topic: Star Destroyer engine ignition effect, need help...!  (Read 38 times)

Offline Often wrong Soong

  • Ensign
  • *
  • Posts: 2
Star Destroyer engine ignition effect, need help...!
« on: May 20, 2018, 03:07:20 pm »
Hi guys, bit of a long post here so thanks if you make it to the end!

I've recently taken the plunge into micro controllers and have been trying to wrap my head around it all for a couple of weeks now.  Unfortunately, I'm really struggling to make much sense of anything passed the real basic stuff and seem to get swamped with it all quite quickly.  I guess my mind just doesn't work very well that way.  I have been tinkering with some of the codes that have been very generously shared by some of you guys here (Gadgetron_3000, RossW, Spencer etc, you guys are awesome for that, thank you!!) and have been able to get most basic stuff I may need but there's one effect that I just can't get to grips with.  I'm positive that it's such an easy thing to achieve too, which really frustrates me, but I'm begging for back-up from better minds than mine!!

Basically, I'm after an engine ignition cycle (for a Star Destroyer or Viper etc) which will fade 3 LED's up and flicker as if at full power, with each starting it's fade/flicker cycle at slightly staggered (but overlapping) timings, before shutting down and fading off, again at staggered overlapping times, after a single button push.  E.g: After a button push LED1 begins to slowly fade up and flicker, LED2 would wait for, say 1sec before beginning it's own fade up and flicker, then LED3 would begin it's cycle slightly after LED2.  Then each LED would shutdown at slightly different timings and fade out.

I've managed to adjust a code shared by Spencer in another thread (http://scifimodelaction.com/sfmaforum/index.php?topic=7135.0) to get the fade up and flicker effect I'm looking for, and have added 2 more LED's to the code, which is great but it only clones the effect over the 3 channels.  I can't for the life of me figure out how to introduce the timing separations so each LED channel starts it's fade/flicker cycle at slightly different times, or even how to include the button push to trigger the whole sequence!


Any help or advice would be very much appreciated, my brain feels like it's leaking out of my ears

Here's the code I've been butchering:

#define LED_FLICKER1_PIN 9        //sets the variable "LED_FLICKER_PIN" to pin number(s), needs to be a pwm pin;
#define LED_FLICKER2_PIN 10
#define LED_FLICKER3_PIN 11

static int lowest_low = 190;
static int highest_low = 200;
static int lowest_high = 200;
static int highest_high = 255;

static int shortest_on = 5;
static int longest_on = 10;
static int shortest_off = 5;
static int longest_off = 8;


static int fade_time = 4000; // time to fade up, in milliseconds


// time keeping
unsigned long currentMillis;
unsigned long flickerMillis;

// various bookeeping things
boolean led_flicker_state = 0;
int on_time;
int off_time;
int high_brightness;
int low_brightness;
int fade_brightness;


void setup() {

  pinMode(LED_FLICKER1_PIN, OUTPUT);   // set pin as output
  pinMode(LED_FLICKER2_PIN, OUTPUT);
  pinMode(LED_FLICKER3_PIN, OUTPUT);

  // intially randomize the params
  low_brightness = random(lowest_low, highest_low);
  high_brightness = random(lowest_high, highest_high);
  on_time = random(shortest_on, longest_on);
  off_time = random(shortest_off, longest_off);
}


void loop() {
  // get the time
  currentMillis = millis();

  if (currentMillis <= fade_time) {
    fade_brightness = int(255.0 * float(currentMillis) / float(fade_time));
    analogWrite(LED_FLICKER1_PIN, fade_brightness);
    analogWrite(LED_FLICKER2_PIN, fade_brightness);
    analogWrite(LED_FLICKER3_PIN, fade_brightness);
  }

  // then the flicker
  else {
    // When it's time to change states, write it out, reset the time and randomize again
    //    for the next time to change states
    if (currentMillis - flickerMillis > (led_flicker_state ? on_time : off_time)) {
      analogWrite(LED_FLICKER1_PIN, (led_flicker_state ? high_brightness : low_brightness));
      analogWrite(LED_FLICKER2_PIN, (led_flicker_state ? high_brightness : low_brightness));
      analogWrite(LED_FLICKER3_PIN, (led_flicker_state ? high_brightness : low_brightness));
      flickerMillis = currentMillis;
      led_flicker_state = !led_flicker_state;
      low_brightness = random(lowest_low, highest_low);
      high_brightness = random(lowest_high, highest_high);
      on_time = random(shortest_on, longest_on);
      off_time = random(shortest_off, longest_off);
    }
  }
}



Congrats on reaching the end of the post....bonus points for stamina!!

Wayne


Offline texastony1946

  • Lieutenant
  • **
  • Posts: 30
Re: Star Destroyer engine ignition effect, need help...!
« Reply #1 on: May 20, 2018, 03:45:14 pm »
I have tried to make this flicker fade work for some time. I accomplished some of this with my Gundam code. Still trying to make it repeat, and not block. Good luck with this one, I am certainly interested in seeing it work.

 




Enterprise © Bloc