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

Login with username, password and session length
 

Author Topic: Need to have three intervals for blinking LEDs instead of two  (Read 315 times)

Offline Mark2000

  • Ensign
  • *
  • Posts: 12
Hi, there folks. I'm writing (really stealing) code to flash the running likes on the TOS Enterprise. Right now I'm using the "blinknodelay" method to blink the saucer and rear strobes independently.

Code: [Select]
   if((ledState2 == HIGH) && (currentMillis - previousMillis4 >= OnTime2))
  {
    ledState2 = LOW;  // Turn it off
    previousMillis4 = currentMillis;  // Remember the time
    digitalWrite(ledPin2, ledState2);  // Update the actual LED
  }
  else if ((ledState2 == LOW) && (currentMillis - previousMillis4 >= OffTime2))
  {
    ledState2 = HIGH;  // turn it on
    previousMillis4 = currentMillis;   // Remember the time
    digitalWrite(ledPin2, ledState2);   // Update the actual LED
  }


The only problem is that this method only seems to allow two state intervals, off and on. I'd like the time the lights so that the saucer goes on for a time and the off (only two intervals needed which sets the amount of time in which all the lights have to do one part of the pattern) and in the middle of the off interval the strobe flashes quickly. That's where I need three intervals to get the timing right off/on/off. Any idea how to do this?

Offline RossW

  • Captain
  • ****
  • Posts: 312
Re: Need to have three intervals for blinking LEDs instead of two
« Reply #1 on: May 25, 2018, 10:13:54 am »
Not sure I totally understand what you are trying to achieve - do you want the strobe to light up only when the saucer running lights are off?

Saucer Pattern

____||||||||||____||||||||||____||||||||||____

Strobe Pattern

_||__________||__________||__________||

Offline Mark2000

  • Ensign
  • *
  • Posts: 12
Re: Need to have three intervals for blinking LEDs instead of two
« Reply #2 on: May 25, 2018, 11:37:53 am »
Yes, that's exactly what I want. What I've managed with my current code is

____llllll____llllll____llllll____llllll____llllll____

ll______ll______ll______ll______ll______ll

Where the strobe comes on right as the saucer blinks go off. It's not a bad look, but I'd prefer the strobe flash in the middle of the saucer off time. That seems to require some padding at the front of the strobe flash and a little less after.

BTW, Ross, I bought a strobe board from you for my last build. Still going strong after 4 years.
« Last Edit: May 25, 2018, 11:59:21 am by Mark2000 »

Offline RossW

  • Captain
  • ****
  • Posts: 312
Re: Need to have three intervals for blinking LEDs instead of two
« Reply #3 on: May 25, 2018, 12:55:23 pm »
Yes, that's exactly what I want. What I've managed with my current code is

____llllll____llllll____llllll____llllll____llllll____

ll______ll______ll______ll______ll______ll

Where the strobe comes on right as the saucer blinks go off. It's not a bad look, but I'd prefer the strobe flash in the middle of the saucer off time. That seems to require some padding at the front of the strobe flash and a little less after.

BTW, Ross, I bought a strobe board from you for my last build. Still going strong after 4 years.

Hey Mark! Thought I recognized you, but it was HT that we last interacted.

Rather than add an additional timing variable, could you make the delay less to the running light OFF value in the first iteration of the main loop so it lines up?

Code: [Select]
runLtsOffVal = 1 sec;
i = 0;

Loop:
  if i = 0 then
    runLtsOffVal = 0.75;
  else
    runLtsOffVal = 1;
  end if




  i = i + 1;

  GOTO Loop


Are you using PICs or Arduinos? If the latter, I can share my running lts/srtrobe lts code for you to play with.

Offline Mark2000

  • Ensign
  • *
  • Posts: 12
Re: Need to have three intervals for blinking LEDs instead of two
« Reply #4 on: May 25, 2018, 02:40:49 pm »
I'm using arduino. I've seen your code in the other thread.Mine is a bit different. The setup looks like this:

Code: [Select]
//rear strobes
int ledPin1 =  4;      // the number of the LED pin
int ledState1 = LOW;             // ledState used to set the LED
unsigned long previousMillis3 = 0;        // will store last time LED was updated
long OnTime1 = 20;           // milliseconds of on-time
long OffTime1 = 1740;          // milliseconds of off-time

//saucer running lights
int ledPin2 =  7;      // the number of the LED pin
int ledState2 = LOW;             // ledState used to set the LED
unsigned long previousMillis4 = 0;        // will store last time LED was updated
long OnTime2 = 750;           // milliseconds of on-time
long OffTime2 = 1010;          // milliseconds of off-time

void loop () {
    unsigned long currentMillis = millis();

//Rear Strobes
  if((ledState1 == HIGH) && (currentMillis - previousMillis3 >= OnTime1))
  {
    ledState1 = LOW;  // Turn it off
    previousMillis3 = currentMillis;  // Remember the time
    digitalWrite(ledPin1, ledState1);  // Update the actual LED
  }
  else if ((ledState1 == LOW) && (currentMillis - previousMillis3 >= OffTime1))
  {
    ledState1 = HIGH;  // turn it on
    previousMillis3 = currentMillis;   // Remember the time
    digitalWrite(ledPin1, ledState1);    // Update the actual LED
  }

//Saucer Running Lights
   if((ledState2 == HIGH) && (currentMillis - previousMillis4 >= OnTime2))
  {
    ledState2 = LOW;  // Turn it off
    previousMillis4 = currentMillis;  // Remember the time
    digitalWrite(ledPin2, ledState2);  // Update the actual LED
  }
  else if ((ledState2 == LOW) && (currentMillis - previousMillis4 >= OffTime2))
  {
    ledState2 = HIGH;  // turn it on
    previousMillis4 = currentMillis;   // Remember the time
    digitalWrite(ledPin2, ledState2);   // Update the actual LED
  }


You're looks similar with an on and off time to set for each set of blinkers. Considering both sequences start at the same time and must last the same length of time, I'm not sure how I could line them up the way I want without a buffer at the start of the strobes.

BTW, is it just me or is code invisible (white text on white) until it's selected? It's doing it to me in every browser.

Offline RossW

  • Captain
  • ****
  • Posts: 312
Re: Need to have three intervals for blinking LEDs instead of two
« Reply #5 on: May 25, 2018, 07:35:39 pm »
I'm using arduino. I've seen your code in the other thread.Mine is a bit different. The setup looks like this:

Code: [Select]
//rear strobes
int ledPin1 =  4;      // the number of the LED pin
int ledState1 = LOW;             // ledState used to set the LED
unsigned long previousMillis3 = 0;        // will store last time LED was updated
long OnTime1 = 20;           // milliseconds of on-time
long OffTime1 = 1740;          // milliseconds of off-time

//saucer running lights
int ledPin2 =  7;      // the number of the LED pin
int ledState2 = LOW;             // ledState used to set the LED
unsigned long previousMillis4 = 0;        // will store last time LED was updated
long OnTime2 = 750;           // milliseconds of on-time
long OffTime2 = 1010;          // milliseconds of off-time

void loop () {
    unsigned long currentMillis = millis();

//Rear Strobes
  if((ledState1 == HIGH) && (currentMillis - previousMillis3 >= OnTime1))
  {
    ledState1 = LOW;  // Turn it off
    previousMillis3 = currentMillis;  // Remember the time
    digitalWrite(ledPin1, ledState1);  // Update the actual LED
  }
  else if ((ledState1 == LOW) && (currentMillis - previousMillis3 >= OffTime1))
  {
    ledState1 = HIGH;  // turn it on
    previousMillis3 = currentMillis;   // Remember the time
    digitalWrite(ledPin1, ledState1);    // Update the actual LED
  }

//Saucer Running Lights
   if((ledState2 == HIGH) && (currentMillis - previousMillis4 >= OnTime2))
  {
    ledState2 = LOW;  // Turn it off
    previousMillis4 = currentMillis;  // Remember the time
    digitalWrite(ledPin2, ledState2);  // Update the actual LED
  }
  else if ((ledState2 == LOW) && (currentMillis - previousMillis4 >= OffTime2))
  {
    ledState2 = HIGH;  // turn it on
    previousMillis4 = currentMillis;   // Remember the time
    digitalWrite(ledPin2, ledState2);   // Update the actual LED
  }


You're looks similar with an on and off time to set for each set of blinkers. Considering both sequences start at the same time and must last the same length of time, I'm not sure how I could line them up the way I want without a buffer at the start of the strobes.

BTW, is it just me or is code invisible (white text on white) until it's selected? It's doing it to me in every browser.
I see the white box, too. At least you can do contractions - whenever I do that everything gets cut off after the single quote.

 




Enterprise © Bloc