Problem. LED model spaceship state engine. Christmas memories when i was a lad

Hi this is my first post on the arduino forum.
Back in the late 70's my dad took me to see the first star trek film . Is was spectacular none of the cg we see today, but fully lit 10 foot long models that looked real .
A few months later there was a big present under the Christmas tree , and you guest it , it was a huge two foot long USS Enterprise kit .... Woooo ! Hoooo ! THANKS DAD !
I then sent off for a few leds and two 555 chips and some resitors and some dolls house 6v pea bulbs.
I was 13 a the time and had big plans for my Enterprise kit. But then i grew up, moved on, wife kids and a job. Never built the enterprise , and almost forgot that lovely Christmas morning when i was a lad.

Roll on some years later ..

Last month i went to see mum and dad to give them a hand sorting out the attic (loads off rubbish to go!) my dad said on the phone. So up the ladder to the loft and turn the light on, and started to pass all the junk down to me dad. And in the far corner of the attic , next to a my old box of slot car track a large box covered in dust. The Enterprise!! Not any old Enterprise kit, my Enterprise kit.
It was the last thing i past down from the attic to my dad. Then sat down for a lovely sunday lunch made by my mum . You never got round to building the spaceship did you! No i didn't dad.
I open the box and forgot that i had put all the components i had sent of for in the box all those years ago. I knew what was coming up next .. (Since my dad retired he contracted caner 2 years ago, and is getting over chemotherapy, and has taken up building model motorbikes cars and trucks.)
Can i have a crack at building the spaceship for you son, and can you download a circuit diagram for me to make the spaceships lights flash. (Dad was in the auto electrical service industry and was a dab hand with a 20w weller iron and a 2mm chisel bit)
Ok dad ! But things have moved on a bit since 555 chips and and dolls house 6v pea bulbs. So i am planing to get some coloured 1.8mm leds and a length of 5v white led strip and a USS Enterprise kit for him for Christmas. And program a Arduino to power his spaceship kit.

I have had fun with my son building Arduino Uno robots, and we have made a obstacle avoiding robot a line following robot, and a arduino android bluetooth HC-05 module smart car. And played with the code to power them with servo or L298N motor modules.

My first port of call was www.gammon.com and download the <LedFlasher.h> and <LedFader.h> library and read his state engine tutorial and have a play with his blink and fade tutorials . Had my sketch up and running after lots of pulling of hair out, and debugging, and looking at what other people have done using the <LedFlasher.h> and <LedFader.h> librarys that Mr Gammon has made.

My sketch is up an running but i have made a schoolboy error and the orange led hangs and wont go back to the blue led!

(Sequence) (Seconds) Startup Sequence 1 sec for each state 1,2,3,4,5,6,7,8,9,10

1 Floodlight. 1 sec on startup /will stay on always
2 Floodlight. 1 sec on startup /will stay on always
3 Floodlight. 1 sec on startup /will stay on always
4 Floodlight. 1 sec on startup /will stay on always
5 Floodlight. 1 sec on startup /will stay on always
6 Floodlight. 1 sec on startup /will stay on always
7 Deflector ORANGE. 1 sec /stays on for 60 secs
8 Navigation green. 1 sec /will stay on always
9 Strobe white. 1 sec /will stay on always
10 Torpedo red. 1 sec /will tern off after 6 secs

11 Deflector BLUE. led will go on after Deflector ORANGE led goes off,and stay on for 60 secs, and Torpedo will go on for 6secs 1,2,3,4,5,6,8,9 will stay on always..

Deflector ORANGE. led will go on after Deflector BLUE led goes off, and stay on for 60 secs, and Torpedo will go on for 6secs 1,2,3,4,5,6,8,9 will stay on always..

Deflector BLUE. led will go on after Deflector ORANGE led goes off, and stay on for 60 secs, and Torpedo will go on for 6secs 1,2,3,4,5,6,8,9 will stay on always..

And so on, and so on,.. in a loop..

Can you point me in the direction to my error i made in my sketch please.

You seem to have forgotten to attach your code? In code tags (</>) please?

I mest up here is the code.

#include <LedFader.h>
#include <LedFlasher.h>

// pin assignments
const byte StrobesPin = 12;   // PWM
const byte NavigationPin = 11;
const byte DeflectorbluePin = 10;   // PWM
const byte DeflectororangePin = 9;    // PWM
const byte TorpedoPin = 8;
const byte FloodsevenPin = 7;
const byte FloodsixPin = 6;   // PWM
const byte FloodfivePin = 5;   // PWM
const byte FloodfourPin = 4;  
const byte FloodthreePin = 3;  // PWM
const byte FloodtwoPin = 2;  

// Faders                           pin           min  max  millis    on?    stop?
LedFader deflectororangeFader (DeflectororangePin, 0,   40,  3000,   false,  true);
LedFader deflectorblueFader   (DeflectorbluePin,   0,   40,  3000,   false,  true);

// Flashers                pin          off-time  on-time       on?
LedFlasher strobes    (StrobesPin,        900,       100,     false);
LedFlasher navigation (NavigationPin,     2900,      100,     false);

// states for the state machine
typedef enum
  {
  initialState,
  wantFloodtwo,                // ALWAYS ON
  wantFloodthree,              // ALWAYS ON
  wantFloodfour,               // ALWAYS ON
  wantFloodfive,               // ALWAYS ON
  wantFloodsix,                // ALWAYS ON
  wantFloodseven,                // ALWAYS ON
  wantNavigation,                // ALWAYS ON
  wantStrobes,                   // ALWAYS ON
  wantTorpedostartup,         // ALWAYS ON
  wantDeflectororangestartup,    // Startup mode
  wantDeflectororangeon,        // Impulse mode
  wantDeflectorblueoff,         // Impulse mode
  wantTorpedoon,             // Impulse mode 
  wantDeflectorblueoffreturn,   // Impulse mode return
  wantDeflectorblueon,          // Warp mode
  wantDeflectororangeoff,       // Warp mode
  wantTorpedooff,             // Warp mode  
  
    
  } states;

// state machine variables
states state = initialState;
unsigned long lastStateChange = 0;
unsigned long timeInThisState = 1000;

void setup ()
  {
  pinMode (FloodtwoPin, OUTPUT);                          
  pinMode (FloodthreePin, OUTPUT);
  pinMode (FloodfourPin, OUTPUT);
  pinMode (FloodfivePin, OUTPUT);
  pinMode (FloodsixPin, OUTPUT);
  pinMode (FloodsevenPin, OUTPUT);
  pinMode (NavigationPin, OUTPUT);
  pinMode (StrobesPin, OUTPUT);
  pinMode (TorpedoPin, OUTPUT);
 
  
  // set up faders, flashers  
  deflectororangeFader.begin ();
  deflectorblueFader.begin ();
  strobes.begin ();
  navigation.begin ();
  }  // end of setup
        
void doStateChange ()
  {
  lastStateChange = millis ();    // when we last changed states
  timeInThisState = 1000;         // default one second between states

  switch (state)
   {
   case initialState:
         state = wantFloodtwo;
         break;
         
    case wantFloodtwo:
         digitalWrite (FloodtwoPin, HIGH);
         state = wantFloodthree;
         break;
         
    case wantFloodthree:
         digitalWrite (FloodthreePin, HIGH);
         state = wantFloodfour;
         break;
         
    case wantFloodfour:
         digitalWrite (FloodfourPin, HIGH);
         state = wantFloodfive;
         break;
         
    case wantFloodfive:
         digitalWrite (FloodfivePin, HIGH);
         state = wantFloodsix;
         break;
         
    case wantFloodsix:
         digitalWrite (FloodsixPin, HIGH);
         state = wantFloodseven;
         break;
         
    case wantFloodseven:
         digitalWrite (FloodsevenPin, HIGH);
         state = wantDeflectororangestartup;
         break;
         
    case wantDeflectororangestartup:
         deflectororangeFader.on();
         state = wantStrobes;
         break;
         
    case wantStrobes:
         strobes.on();
         state = wantNavigation;
         break;
         
    case wantNavigation:
         navigation.on();
         state = wantTorpedostartup;
         break;
         
    case wantTorpedostartup:
         digitalWrite (TorpedoPin, HIGH);
         state = wantDeflectororangeoff;              
         timeInThisState = 6000;
         break;
         
//impulse mode
    case wantDeflectorblueoff:
         deflectorblueFader.off();
         state = wantDeflectorblueoffreturn;
         break;
        
    case wantDeflectorblueoffreturn:
         deflectororangeFader.on(); 
         state = wantTorpedoon;
         break;
         
    case wantTorpedoon:
         digitalWrite (TorpedoPin, HIGH);
         state = wantDeflectorblueoff;
         
         timeInThisState = 6000;  
         break;
         
 // warp mode   
    case wantDeflectororangeoff:   
         deflectororangeFader.off();
         state = wantDeflectorblueon;
         break;
        
    case wantDeflectorblueon:
         deflectorblueFader.on();
         state = wantTorpedooff;
         break;
         
    case wantTorpedooff:  
         digitalWrite (TorpedoPin, LOW);
         state = wantDeflectorblueoff;
         
         timeInThisState = 6000;  
         break;     
    
         
    }  // end of switch on state
  }  // end of doStateChange


void loop ()
  {
   if (millis () - lastStateChange >= timeInThisState)
     doStateChange ();
   // update faders, flashers
   deflectororangeFader.update ();
   deflectorblueFader.update ();
   navigation.update ();
   strobes.update ();
  // other stuff here like testing switches
  }  // end of loop

I spotted a discrepancy in the pattern below:

    case wantTorpedostartup:
         digitalWrite (TorpedoPin, HIGH);
         state = wantDeflectororangeoff; <-- should be wantDeflectorblueoff ?
         timeInThisState = 6000;
         break;
         
//impulse mode
    case wantDeflectorblueoff:

Thanks for the help PaulRB ! but now it only gets to the (ORANGE impulse led mode) and will not initiate the (BLUE warp led mode)

In my code it went through at all states, Start up--ORANGE impulse led mode--BLUE warp led mode--then back to--ORANGE impulse led mode. And hangs on (ORANGE impulse led mode with a small pause on the led every 6 seconds , and will not loop back to--BLUE warp led mode--?

I have added some notes to the code below . I cant for the life of me see what i have done wrong it all looks in logical order to me.

Just one mist placed bit of code ! But what the hell is it ? Its driving me nuts....

  {
  initialState,
  wantFloodtwo,               // always on     Flood light two   on
  wantFloodthree,             // always on   Flood light three   on
  wantFloodfour,              // always on    Flood light four   on
  wantFloodfive,              // always on    Flood light five   on
  wantFloodsix,               // always on     Flood light six   on
  wantFloodseven,             // always on   Flood light seven   on
  wantNavigation,             // always on    Navigation light   on 
  wantStrobes,                // always on      Strobes light    on
  wantTorpedostartup,         // always on         Torpedo           startup
  wantDeflectororangestartup, // Startup mode  Deflector orange      startup
  wantDeflectororangeon,      // Impulse mode  Deflector orange  on
  wantDeflectorblueoff,       // Impulse mode  Deflector blue    off 
  wantTorpedoon,              // Impulse mode      Torpedo       on 
  wantDeflectorblueoffreturn, // Impulse mode  Deflector blue    off  return 
  wantDeflectorblueon,        // Warp mode     Deflector blue    on
  wantDeflectororangeoff,     // Warp mode     Deflector orange  off
  wantTorpedooff,             // Warp mode         Torpedo       off
  
    
  } states;

// state machine variables
states state = initialState;
unsigned long lastStateChange = 0;
unsigned long timeInThisState = 1000;

void setup ()
  {
  pinMode (FloodtwoPin, OUTPUT);        //     white       led                       
  pinMode (FloodthreePin, OUTPUT);      //     white       led 
  pinMode (FloodfourPin, OUTPUT);       //     white       led 
  pinMode (FloodfivePin, OUTPUT);       //     white       led 
  pinMode (FloodsixPin, OUTPUT);        //     white       led 
  pinMode (FloodsevenPin, OUTPUT);      //     white       led 
  pinMode (NavigationPin, OUTPUT);      //     green       led 
  pinMode (StrobesPin, OUTPUT);         //  bright white   led 
  pinMode (TorpedoPin, OUTPUT);         //      red        led
 
  
  // set up faders, flashers  
  deflectororangeFader.begin ();     //  orange fader      led  begin
  deflectorblueFader.begin ();       //   blue fader       led  begin
  strobes.begin ();                  // strob flasher      led  begin
  navigation.begin ();               // navigation flasher led  begin
  }  // end of setup
        
void doStateChange ()
  {
  lastStateChange = millis ();       // when we last changed states
  timeInThisState = 1000;            // default one second between states

  switch (state)
   {
      case initialState:               
         state = wantFloodtwo;             //  want flood light two white led  
         break;
         
    case wantFloodtwo:
         digitalWrite (FloodtwoPin, HIGH); //       flood light two white led
         state = wantFloodthree;           //want flood light three white led
         break;
         
    case wantFloodthree:
         digitalWrite (FloodthreePin, HIGH); //   flood light three white led
         state = wantFloodfour;           //  want flood light four white led
         break;
         
    case wantFloodfour:
         digitalWrite (FloodfourPin, HIGH); //     flood light four white led
         state = wantFloodfive;           //  want flood light five white led
         break;
         
    case wantFloodfive:
         digitalWrite (FloodfivePin, HIGH); //     flood light five white led
         state = wantFloodsix;            //   want flood light six white led
         break;
         
    case wantFloodsix:
         digitalWrite (FloodsixPin, HIGH); //       flood light six white led
         state = wantFloodseven;          // want flood light seven white led
         break;
         
         // deflector orange, strobe, navigation , torpedo , leds from hereon. 
         
         case wantFloodseven:
         digitalWrite (FloodsevenPin, HIGH);//   flood light seven white led
         state = wantDeflectororangestartup;//want deflectof orange led STARTUP
         break;
         
    case wantDeflectororangestartup:       //want deflector orange led  STARTUP
         deflectororangeFader.on();        //     deflector orange led  FADER ON
         state = wantStrobes;              //    want strobe white led
         break;
         
    case wantStrobes:                      //    want strobe white led
         strobes.on();                     //     strobe     white led      ON
         state = wantNavigation;           //want navigation green led      ON
         break;
         
    case wantNavigation:                   //want navigation green led       
         navigation.on();                  //     navigation green led      ON
         state = wantTorpedostartup;       //want torpedo red led       STARTUP
         break;
         
    case wantTorpedostartup:               //want torpedo red led       STARTUP 
         digitalWrite (TorpedoPin, HIGH);  //      torpedo red led 
         state = wantDeflectororangeoff;   //want deflector orange led     OFF             
         timeInThisState = 6000;
         break;
         
         //impulse mode or call it the (orange impuse led mode!) 
         
         //impulse mode               
    case wantDeflectorblueoff:              //want deflector blue  led     OFF
         deflectorblueFader.off();          //  deflector blue     led     OFF
         state = wantDeflectorblueoffreturn;//want deflector blue led OFF RETURN
         break;
        
    case wantDeflectorblueoffreturn:       //want deflector blue led  OFF RETURN
         deflectororangeFader.on();        //  deflector orange  led  fader ON
         state = wantTorpedoon;            //  want torpedo red  led        ON 
         break;
         
    case wantTorpedoon:                    //  want torpedo red  led 
         digitalWrite (TorpedoPin, HIGH);  //     torpedo   red  led
         state = wantDeflectorblueoff;     //want deflector blue led       OFF
         
         timeInThisState = 6000;  
         break;
         
         // warp mode or call it the (blue warp led mode!) 
         
         // warp mode   
    case wantDeflectororangeoff:         // want deflector orange led      OFF   
         deflectororangeFader.off();     //   deflector orange    led      OFF 
         state = wantDeflectorblueon;    // want deflector  blue  led      ON
         break;
        
    case wantDeflectorblueon:            //  want deflector blue  led      ON
         deflectorblueFader.on();        // deflector blue fader  led      ON
         state = wantTorpedooff;         //   want torpedo red    led      OFF
         break;
         
    case wantTorpedooff:                  //  want torpedo red    led      OFF
         digitalWrite (TorpedoPin, LOW);  //     torpedo red      led
         state = wantDeflectorblueoff;    // want deflector blue  led      OFF
         
         timeInThisState = 6000;  
         break;
    
    
    
   }  // end of switch on state
  }  // end of do State Change


void loop ()
  {
   if (millis () - lastStateChange >= timeInThisState)
     doStateChange ();
   // update faders, flashers
   deflectororangeFader.update ();
   deflectorblueFader.update ();
   navigation.update ();
   strobes.update ();
   
  }  // end of loop

Try this:

#include <LedFader.h>
#include <LedFlasher.h>

// pin assignments
const byte StrobesPin = 12;   // PWM
const byte NavigationPin = 11;
const byte DeflectorbluePin = 10;   // PWM
const byte DeflectororangePin = 9;    // PWM
const byte TorpedoPin = 8;
const byte FloodsevenPin = 7;
const byte FloodsixPin = 6;   // PWM
const byte FloodfivePin = 5;   // PWM
const byte FloodfourPin = 4; 
const byte FloodthreePin = 3;  // PWM
const byte FloodtwoPin = 2; 

// Faders                           pin           min  max  millis    on?    stop?
LedFader deflectororangeFader (DeflectororangePin, 0,   40,  3000,   false,  true);
LedFader deflectorblueFader   (DeflectorbluePin,   0,   40,  3000,   false,  true);

// Flashers                pin          off-time  on-time       on?
LedFlasher strobes    (StrobesPin,        900,       100,     false);
LedFlasher navigation (NavigationPin,     2900,      100,     false);

// states for the state machine
typedef enum
  {
  initialState,
  wantFloodtwo,                // ALWAYS ON
  wantFloodthree,              // ALWAYS ON
  wantFloodfour,               // ALWAYS ON
  wantFloodfive,               // ALWAYS ON
  wantFloodsix,                // ALWAYS ON
  wantFloodseven,                // ALWAYS ON
  wantNavigation,                // ALWAYS ON
  wantStrobes,                   // ALWAYS ON
  wantTorpedostartup,         // ALWAYS ON
  wantDeflectororangestartup,    // Startup mode
  wantDeflectororangeon,        // Impulse mode
  wantDeflectorblueoff,         // Impulse mode
  wantTorpedoon,             // Impulse mode
  wantDeflectorblueoffreturn,   // Impulse mode return
  wantDeflectorblueon,          // Warp mode
  wantDeflectororangeoff,       // Warp mode
  wantTorpedooff,             // Warp mode 
 
   
  } states;

// state machine variables
states state = initialState;
unsigned long lastStateChange = 0;
unsigned long timeInThisState = 1000;

void setup ()
  {
  pinMode (FloodtwoPin, OUTPUT);                         
  pinMode (FloodthreePin, OUTPUT);
  pinMode (FloodfourPin, OUTPUT);
  pinMode (FloodfivePin, OUTPUT);
  pinMode (FloodsixPin, OUTPUT);
  pinMode (FloodsevenPin, OUTPUT);
  pinMode (NavigationPin, OUTPUT);
  pinMode (StrobesPin, OUTPUT);
  pinMode (TorpedoPin, OUTPUT);
 
 
  // set up faders, flashers 
  deflectororangeFader.begin ();
  deflectorblueFader.begin ();
  strobes.begin ();
  navigation.begin ();
  }  // end of setup
       
void doStateChange ()
  {
  lastStateChange = millis ();    // when we last changed states
  timeInThisState = 1000;         // default one second between states

  switch (state)
   {
   case initialState:
         state = wantFloodtwo;
         break;
         
    case wantFloodtwo:
         digitalWrite (FloodtwoPin, HIGH);
         state = wantFloodthree;
         break;
         
    case wantFloodthree:
         digitalWrite (FloodthreePin, HIGH);
         state = wantFloodfour;
         break;
         
    case wantFloodfour:
         digitalWrite (FloodfourPin, HIGH);
         state = wantFloodfive;
         break;
         
    case wantFloodfive:
         digitalWrite (FloodfivePin, HIGH);
         state = wantFloodsix;
         break;
         
    case wantFloodsix:
         digitalWrite (FloodsixPin, HIGH);
         state = wantFloodseven;
         break;
         
    case wantFloodseven:
         digitalWrite (FloodsevenPin, HIGH);
         state = wantDeflectororangestartup;
         break;
         
    case wantDeflectororangestartup:
         deflectororangeFader.on();
         state = wantStrobes;
         break;
         
    case wantStrobes:
         strobes.on();
         state = wantNavigation;
         break;
         
    case wantNavigation:
         navigation.on();
         state = wantTorpedostartup;
         break;
         
    case wantTorpedostartup:
         digitalWrite (TorpedoPin, HIGH);
         state = wantDeflectorblueoff; // was wantDeflectororangeoff;             
         timeInThisState = 6000;
         break;
         
//impulse mode
    case wantDeflectorblueoff:
         deflectorblueFader.off();
         state = wantDeflectorblueoffreturn;
         break;
       
    case wantDeflectorblueoffreturn:
         deflectororangeFader.on();
         state = wantTorpedoon;
         break;
         
    case wantTorpedoon:
         digitalWrite (TorpedoPin, HIGH);
         state = wantDeflectororangeoff; //was wantDeflectorblueoff;
         
         timeInThisState = 6000; 
         break;
         
 // warp mode   
    case wantDeflectororangeoff:   
         deflectororangeFader.off();
         state = wantDeflectorblueon;
         break;
       
    case wantDeflectorblueon:
         deflectorblueFader.on();
         state = wantTorpedooff;
         break;
         
    case wantTorpedooff: 
         digitalWrite (TorpedoPin, LOW);
         state = wantDeflectorblueoff;
         
         timeInThisState = 6000; 
         break;     
   
         
    }  // end of switch on state
  }  // end of doStateChange


void loop ()
  {
   if (millis () - lastStateChange >= timeInThisState)
     doStateChange ();
   // update faders, flashers
   deflectororangeFader.update ();
   deflectorblueFader.update ();
   navigation.update ();
   strobes.update ();
  // other stuff here like testing switches
  }  // end of loop

Thanks PaulRB ! Almost , it will now go from (ORANGE impulse led mode) to (BLUE warp led mode) and loop back and forth .

But it has lost the torpedo fire in the (BLUE warp led mode) ? and when it enters start up mode on (ORANGE impulse led mode) the mode will execute twice before moving to the (BLUE warp led mode) that has now lost its (torpedo fire) burst in (BLUE warp led mode).

This is what im trying to achieve .

1 Floodlight. 1 sec on startup /will stay on always
2 Floodlight. 1 sec on startup /will stay on always
3 Floodlight. 1 sec on startup /will stay on always
4 Floodlight. 1 sec on startup /will stay on always
5 Floodlight. 1 sec on startup /will stay on always
6 Floodlight. 1 sec on startup /will stay on always
7 Deflector ORANGE. 1 sec /stays on for 60 secs
8 Navigation green. 1 sec /will stay on always
9 Strobe white. 1 sec /will stay on always
10 Torpedo red. 1 sec /will tern on and off in (ORANGE impulse led mode) and (BLUE warp led mode)

11 Deflector BLUE. led will go on after Deflector ORANGE led goes off,and stay on for 60 secs, and Torpedo will go on for 6secs 1,2,3,4,5,6,8,9 will stay on always..

Deflector ORANGE. led will go on after Deflector BLUE led goes off, and stay on for 60 secs, and Torpedo will go on for 6secs 1,2,3,4,5,6,8,9 will stay on always..

Deflector BLUE. led will go on after Deflector ORANGE led goes off, and stay on for 60 secs, and Torpedo will go on for 6secs 1,2,3,4,5,6,8,9 will stay on always..

And so on, and so on,.. in a loop..

Thanks PaulRB.. Im off to pull some more hair out. But the (ORANGE impulse led mode) and (BLUE warp led mode) are working, and are looping .. But where the hell has the Torpedo red led gone in (BLUE warp led mode)???

Rich, no need to repeat things you already posted, unless you changed it somehow?

Your description of the sequence is confusing. For example, item 7 (deflector ORANGE) and what I assume was meant to be item 12 (also deflector ORANGE) don't seem to agree with each other.

Also you say "Torpedo will go on for 6secs 1,2,3,4,5,6,8,9 will stay on always" which I can't understand.

I wonder if what you posted is not supposed to be a sequence, just a numbered list of the leds?

I suggest you write out a time-line marked in seconds and mark where leds go on and off on that time-line. That will help us understand what you want, and maybe clarify some things for you also.

Hi Paul . You are right ! Looking back at my explanation on the lighting sequence for my fathers spaceship model i have got him for Christmas , i can see it is confusing . I have a link to a Youtube video and a photo that i hope will make it clear what i want to achieve for my fathers model .
Sorry but i did slip into some (Treker) jargon that may have led to even more confusion.

(Treker) jargon...
It was noted in the original 70s 80s film that when the enterprise was at (warp speed) faster than light, and (impulse speed) sub light speed, the concave round part on lower front of hull would change colour , Orange for (impulse speed) and Blue for (warp speed) .
To achieve this the model will use two leds, one orange and one blue led side by side or i might get a rgb led to light up the deflector dish . Hence the code states Deflectororande and Deflectorblue.

Explanation of what i want to achieve on the deflector dish ....
In my code i have the Deflectororange and Deflectorblue running for 6 seconds on each colour change(but in reality i will have each colour running for a period of two minutes or more) i only have each colour state for 6 secs in my code for evaluation purposes on my breadboard.
So the Deflector orange and Deflector blue will run for 2 mins in each colour state . Orange for 2 mins then Blue for 2 mins, and then loop back and forth, Orange, Blue, Orange, Blue, until it is turned off.

Now for the torpedo bit! (RED torpedo led)
In the photo of the enterprise you will see the two torpedo launchers (two red lights above the deflector dish)
When the deflector dish changes its state to Blue or Orange for its 2 min state in each colour, at the start of each colour i would like the (RED torpedo led) to go on for 6 secs, as in my code i posted.
So its.. (Deflector orange) state on for 2 mins with the (RED torpedo led) going on for 6sec when (Deflector orange) state starts . Then (Deflector blue) state on for 2 mins with the (RED torpedo led) going on for 6sec when (Deflector blue) state starts , in the start of the Orange, Blue, Orange, Blue, loop until it is turned off.

Now for the explanation of the start up sequence. (floodlights, navigation lights,and strobe beacons)
In the Youtube video, i have put a link to below, you will see the enterprise starting up in the space dock. You will see a sequence of floodlights going on at one second intervals to light the model up(this was done in the film to give the enterprise a sense of presence of the nine foot long model when flying in space, if the navigation lights and strobe beacons were only shown it would only be just a black silhouette with flashing lights)
After the floodlights came on in sequence the orange deflector dish would glow. followed by the navigation lights then finely the strobe beacons.
Each of the above steps will happen at one sec intervals on what i call (start up) in the code i have posted.

Obviously the floodlights, strobes and beacons will (stay on always) after the (start up) sequence. Until the model is turned off.

Here is the time line of the code for my Dads model spaceship he wants to build. (i will try my best)

Here goes!!

(1) Enterprise (start up)

Enterprise floodlights go on at one sec intervals . one to six.....

Floodlight 1.
Floodlight 2.
Floodlight 3.
Floodlight 4.
Floodlight 5.
Floodlight 6. (one sec later the Deflector orange led goes on) and stays on for 2 mins

Deflector orange led is now on. (one sec later the navigation flasher starts)

Navigation flasher led is now on. (one sec later the strobe beacon starts)

Strobes and beacons leds are now on.

(2) (End of Enterprise start up sequence) Now for the loop-return.. (Deflector orange has been on for 2 mins) so now its time for the next state . (turn Deflector BLUE on )

(3) Deflector BLUE is now (on) and will stay on for 2 mins. BUT when Deflector BLUE starts the TORPEDO red will light up for 6 secs . As shown in my code... Deflector BLUE has been on for 2 mins, now (Deflector orange) will start up....

(4) Deflector ORANGE is now (on) and will stay on for 2 mins. BUT when Deflector ORANGE starts the TORPEDO red will light up for 6 secs . Deflector ORANGE has been on for 2 mins, now (Deflector BLUE) will start up.... Now loop-return to (3) then to (4) to (3) to (4) in a loop forever... or till i tern it off!

Floodlights, Strobes and beacons, will always stay on after the (start up) sequence, as shown in my code..

Youtube video. Star Trek The Motion Picture The ORIGINAL Leaving Drydock Sequence 1979

Your description of the sequence is still too elaborate. It communicates enthusiasm and is engaging, which is great. But you also need to be able to write more like a programmer, like a program in fact. Write the description of the sequence as three columns. In column 1 write only the time elapsed in minutes & seconds since the start of the sequence. In column 2 write only the name of the led. In column 3 write only the action: on/off/begin flashing/begin fade on/begin fade off/ etc.

Had another tinker (then a bebug) with Pauls code he posted, but i still have lost the torpedo fire at the end of deflector blue fade , and still i cant stop the hang on the orange led and its constant looping.

Paul this i my interpretation of ons and offs in a state engine .
1 I have all start and stops on the blue and orange modes set to 6 seconds in my interpretation.
2 The blue and orange modes shown in my interpretation show the torpedo going on for a 2 sec duration towards the end of the blue and orange modes .
3 The ((loop start)) and (end of loop.. return to ((loop start)) means that it must loop back and forth .
4 I could not work out how to show the start up, Floodlights, Deflector, Navigation, Strobe staying on all the time. So just try to imagine they stay on all the time after start up. (as shown in my sketch)
Deflector orange will stay on for 6 secs even though the start up shows one second gaps (1 to 9)

I hope this naive way of interpreting a state engine with offs and ons makes sense

Seconds

1 Floodlight /on/
2 Floodlight /on/
3 Floodlight /on/
4 Floodlight /on/
5 Floodlight /on/ Seconds
6 Floodlight /on/
7 Deflector orange /fade on begin/(on for 6 secs)1
8 Navigation /flasher on begin/------------------2
9 Strobe /flasher on begin/-------------------3
---------------------------------------------------4
---------------------------------------------------5-----torpedo on (on for 2 secs)
-----------------------Deflector orange /fade off 6-----torpedo off
.
------Deflector blue /fade on begin/(on for 6 secs)1----((loop start))
---------------------------------------------------2
---------------------------------------------------3
---------------------------------------------------4
---------------------------------------------------5----torpedo on (on for 2 secs)
-------------------------Deflector blue/fade off 6----torpedo off
.
------Deflector orange /fade on begin/(on for 6 secs)1
---------------------------------------------------2
---------------------------------------------------3
---------------------------------------------------4-----torpedo on (on for 2 secs)
---------------------------------------------------5
--------------------Deflector orange/fade off----6-----torpedo off
.
. (end of loop.. return to ((loop start))

That's still pretty confusing. Maybe the formatting you typed in has been lost. Try putting code tags around it. The columns I suggested, if that's what you tried to do, have gone wonky!

richosino:
I could not work out how to show the start up, Floodlights, Deflector, Navigation, Strobe staying on all the time.

The way I meant for you do do it was such that if you say, for example, at 4seconds, floodlight 4 goes on, and then you never say when it goes off, then it never goes off. Also, if you want a blue led to stay on for 6 seconds starting at 9 seconds, you would say "9s: blue led on" and then, later, "15s: blue led off".

Yes it did go, wonky! Paul .
I have now used slashes instead of full stops. So after editing it is now in line..

Now does my last post make a bit more sense after editing ?

If you run my sketch (on my very first post) on a breadboard . You will see that when the state engine gets to orange led it hangs on orange mode and loops ! And the torpedo led does not fire ?

But in my first sketch i posted the floodlights, navigation, and strobe flashers, work fine and keep going all the time in all states of the state engine..! No problems ..

Forget the first blocks of code (it works) No problems....

My sketch is dysfunctional on the last blocks of code..

------Deflector blue /fade on begin/(on for 6 secs)1----((loop start))
---------------------------------------------------2
---------------------------------------------------3
---------------------------------------------------4
---------------------------------------------------5----torpedo on (on for 2 secs)
-------------------------Deflector blue/fade off 6----torpedo off
.
------Deflector orange /fade on begin/(on for 6 secs)1
---------------------------------------------------2
---------------------------------------------------3
---------------------------------------------------4-----torpedo on (on for 2 secs)
---------------------------------------------------5
--------------------Deflector orange/fade off----6-----torpedo off
.
. (end of loop.. return to ((loop start))

Sorry to be a pain, but it doesn't look much different to me. Seconds on the left, sometimes on the right, sometimes both... actions in different columns.... it may make sense to you but still looks a bit of a mess to me, and probably to others.

Being a programmer is about being a bit OCD I'm afraid... because computers (including Arduinos) are the the most OCD things ever!

Have another go at the format I suggested. Be as close to 100% strict with yourself as you can. It's a pain, i know, but it will really clarify things for you and everyone else.

How about if we forget about the floodlights, navigation, and strobe flashers, in my sketch as it seems to be causing confusion . And as the floodlights, navigation, and strobe flashers are working ok. So lets forget them . And just concentrate on the part of the code i cant get to work. And thats the (Deflector orange) and (Deflector blue) and the torpedo red led.

Deflector orange led on for 6 seconds. (LED ORANGE ON)
When the Deflector orange led is on the torpedo red led goes on for (2 seconds) at the end of the 6 seconds of the orange led being on for its 6 second period. (LED ORANGE OFF)

Deflector blue led on for 6 seconds. (LED BLUE ON)
When the Deflector blue led is on the torpedo red led goes on for (2 seconds) at the end of the 6 seconds of the blue led being on for its 6 second period. (LED BLUE OFF)

Deflector orange led on for 6 seconds. (LED ORANGE ON)
When the Deflector orange led is on the torpedo red led goes on for (2 seconds) at the end of the 6 seconds of the orange led being on for its 6 second period. (LED ORANGE OFF)

Deflector blue led on for 6 seconds. (LED BLUE ON)
When the Deflector blue led is on the torpedo red led goes on for (2 seconds) at the end of the 6 seconds of the blue led being on for its 6 second period. (LED BLUE OFF)

If anyone could find the time to have a look at my code, and point out the mistake i have made to why its not cycling correctly

This is turning into "Groundhog Day". If you don't understand what I'm asking, please say so. Don't just repeat yourself in the same ambiguous way you have already done several times.

I'll give it one more try. If this does not work, I can't help any more until you give me that unambiguous list of timed events I asked for.

#include <LedFader.h>
#include <LedFlasher.h>

// pin assignments
const byte StrobesPin = 12;   // PWM
const byte NavigationPin = 11;
const byte DeflectorbluePin = 10;   // PWM
const byte DeflectororangePin = 9;    // PWM
const byte TorpedoPin = 8;
const byte FloodsevenPin = 7;
const byte FloodsixPin = 6;   // PWM
const byte FloodfivePin = 5;   // PWM
const byte FloodfourPin = 4; 
const byte FloodthreePin = 3;  // PWM
const byte FloodtwoPin = 2; 

// Faders                           pin           min  max  millis    on?    stop?
LedFader deflectororangeFader (DeflectororangePin, 0,   40,  3000,   false,  true);
LedFader deflectorblueFader   (DeflectorbluePin,   0,   40,  3000,   false,  true);

// Flashers                pin          off-time  on-time       on?
LedFlasher strobes    (StrobesPin,        900,       100,     false);
LedFlasher navigation (NavigationPin,     2900,      100,     false);

// states for the state machine
typedef enum
  {
  initialState,
  wantFloodtwo,                // ALWAYS ON
  wantFloodthree,              // ALWAYS ON
  wantFloodfour,               // ALWAYS ON
  wantFloodfive,               // ALWAYS ON
  wantFloodsix,                // ALWAYS ON
  wantFloodseven,                // ALWAYS ON
  wantNavigation,                // ALWAYS ON
  wantStrobes,                   // ALWAYS ON
  wantTorpedostartup,         // ALWAYS ON
  wantDeflectororangestartup,    // Startup mode
  wantDeflectororangeon,        // Impulse mode
  wantDeflectorblueoff,         // Impulse mode
  wantTorpedoon,             // Impulse mode
  wantTorpedoon2,             // Impulse mode
  wantDeflectorblueoffreturn,   // Impulse mode return
  wantDeflectorblueon,          // Warp mode
  wantDeflectororangeoff,       // Warp mode
  wantTorpedooff,             // Warp mode 
 
   
  } states;

// state machine variables
states state = initialState;
unsigned long lastStateChange = 0;
unsigned long timeInThisState = 1000;

void setup ()
  {
  pinMode (FloodtwoPin, OUTPUT);                         
  pinMode (FloodthreePin, OUTPUT);
  pinMode (FloodfourPin, OUTPUT);
  pinMode (FloodfivePin, OUTPUT);
  pinMode (FloodsixPin, OUTPUT);
  pinMode (FloodsevenPin, OUTPUT);
  pinMode (NavigationPin, OUTPUT);
  pinMode (StrobesPin, OUTPUT);
  pinMode (TorpedoPin, OUTPUT);
 
 
  // set up faders, flashers 
  deflectororangeFader.begin ();
  deflectorblueFader.begin ();
  strobes.begin ();
  navigation.begin ();
  }  // end of setup
       
void doStateChange ()
  {
  lastStateChange = millis ();    // when we last changed states
  timeInThisState = 1000;         // default one second between states

  switch (state)
   {
   case initialState:
         state = wantFloodtwo;
         break;
         
    case wantFloodtwo:
         digitalWrite (FloodtwoPin, HIGH);
         state = wantFloodthree;
         break;
         
    case wantFloodthree:
         digitalWrite (FloodthreePin, HIGH);
         state = wantFloodfour;
         break;
         
    case wantFloodfour:
         digitalWrite (FloodfourPin, HIGH);
         state = wantFloodfive;
         break;
         
    case wantFloodfive:
         digitalWrite (FloodfivePin, HIGH);
         state = wantFloodsix;
         break;
         
    case wantFloodsix:
         digitalWrite (FloodsixPin, HIGH);
         state = wantFloodseven;
         break;
         
    case wantFloodseven:
         digitalWrite (FloodsevenPin, HIGH);
         state = wantStrobes;
         break;
         
    case wantStrobes:
         strobes.on();
         state = wantNavigation;
         break;
         
    case wantNavigation:
         navigation.on();
         state = wantDeflectororangestartup;
         break;
         
//impulse mode
    case wantDeflectororangestartup:
         deflectororangeFader.on();
         state = wantTorpedoon;
         timeInThisState = 6000;
         break;
         
    case wantTorpedoon:
         digitalWrite (TorpedoPin, HIGH);
         state = wantDeflectororangeoff;         
         timeInThisState = 2000;
         break;
         
    case wantDeflectororangeoff:   
         digitalWrite (TorpedoPin, LOW);
         deflectororangeFader.off();
         state = wantDeflectorblueon;
         break;
       
 // warp mode   
    case wantDeflectorblueon:
         deflectorblueFader.on();
         state = wantTorpedoon2;
         timeInThisState = 6000;
         break;
         
    case wantTorpedoon2:
         digitalWrite (TorpedoPin, HIGH);
         state = wantDeflectorblueoff;         
         timeInThisState = 2000;
         break;
         
    case wantDeflectorblueoff:
         digitalWrite (TorpedoPin, LOW);
         //deflectorblueFader.off();
         state = wantDeflectororangestartup;
         break;
   
         
    }  // end of switch on state
  }  // end of doStateChange


void loop ()
  {
   if (millis () - lastStateChange >= timeInThisState)
     doStateChange ();
   // update faders, flashers
   deflectororangeFader.update ();
   deflectorblueFader.update ();
   navigation.update ();
   strobes.update ();
  // other stuff here like testing switches
  }  // end of loop

Any better? If not please reply in this format:

Time	Led	Action
1s	Flood 2	On
2s	Flood 3	On
3s	Flood 4	On
4s	Flood 5	On
5s	Flood 6	On
6s	Flood 7	On
7s	Strobes	Flash
8s	Navigation	Flash
9s	Deflector Orange	Fade on
15s	Torpedo	On
17s	Torpedo	Off
17s	Deflector Orange	Fade off
18s	Deflector Blue	Fade On
24s	Torpedo	On
26s	Torpedo	Off
27s	Deflector Blue	Fade off
27s	-	Goto 9s

Thanks again Paul.
I can now see how you wanted me to show the time line of the state engine .
My explanation on the lighting sequence was totally confusing, and i put the seconds on the wrong side of the time line.

You hit the nail on the head with the time line you posted (just what i wanted)

But unfortunately the (27s - Goto 9s) does not happen ! I starts a strange loop ?

8s Navigation Flash
9s Deflector Orange Fade on
15s Torpedo On
17s Torpedo Off
17s Deflector Orange Fade off
18s Deflector Blue Fade On
24s Torpedo On
26s Torpedo Off
27s Deflector Blue Fade off
27s - Goto 9s (Does not loop back to 9s) Runs fine up to here

27s Deflector Blue Fade on
33s Deflector Orange Fade on------------------------------(Blue is still on at this point)
33s Deflector Blu Fade off
33s Deflector Blu Fade on (and momentarily goes out for a bit)
33s Deflector Orange Fade off------------------------------(Blue is still on at this point)
34s Deflector Blue Fade on (after it momentarily went out for a bit)
40s - Goto 27s

All im saying is from 27s to 40s it all goes wrong . If it were to loop from (27s - Goto 9s) it would be perfect and just what i want for my dads model spaceship .

Sorry to be a pain Paul (you almost hit it on the head) thanks again for your help..

My bad this time. Look here, i left a line of code commented out:

    case wantDeflectorblueoff:
         digitalWrite (TorpedoPin, LOW);
         //deflectorblueFader.off();
         state = wantDeflectororangestartup;
         break;

I could not find the flasher and fader libraries you are using, so i had to comment out all the lines of code associated with them to check the whole sketch compiled ok. Then i un-commented the lines again. But i missed one.

Thanks Paul thats nailed it.

I have noted that the (return) command was not needed when i compared the two programs side by side , and you added a (torpedo2 command)

But when i loaded up the sketch to my breadboard to physically see it working i noted a strange anomaly on the fade blue and orange !

/ / Faders-------------pin-------------------------min-max---millis----on?---stop?
LedFader deflectororangeFader (DeflectororangePin, 0, 200, 10000, false, true);
LedFader deflectorblueFader (DeflectorbluePin, 0, 200, 10000, false, true);

This is what i see (physically) on my breadboard.... Strange ??

LED orange fades up (and stays on for 10 secs ---and when the torpedo red goes on for its 1 sec interval , the orange led does not fade down it just goes out? no fade down, just goes off...

Obviously the first thing that came to mind was that i had not given enough time in the program for the orange led to fade up and down. So i set the the (timeInThisState) to 12000 (12 seconds) thinking that would cure the anomaly.. but i had the same strange
anomaly. Orange led fade up, but with no fade down, just OFF? this also happens on the blue fade up and blue fade down, the blue just goes OFF, no fade down ?

Paul the sketch works fine, just how i wanted it to work for my Dads spaceship. Thanks again Paul for the help.

Nick Gammons <LedFader.h> <LedFlasher.h> libraries can be found at the link below .

Its a shame about the irritating (OFF) on fade down on the orange and blue leds . Any ideas on whats going on? Strange ?

This is the test program i used to test the leds and resistors and timing on my breadboard. I works perfectly on fade up, and fade down .

#include <LedFader.h>

// set up some LEDs
//                 pin  min max  millis
LedFader orange     (3, 0, 100,  6000);
LedFader blue       (5, 0, 100,  6000);

void setup() 
  {      
  orange.begin ();
  blue.begin   ();
  }  // end of setup

void loop() 
  {
  // update lights
  orange.update ();
  blue.update ();
  
 }  // end of loop

richosino:
Nick Gammons <LedFader.h> <LedFlasher.h> libraries can be found at the link below .

Gammon Forum : Electronics : Microprocessors : How to do multiple things at once ... like cook bacon and eggs

Its a shame about the irritating (OFF) on fade down on the orange and blue leds . Any ideas on whats going on? Strange ?

OK, I just read through the relevant lines of code in that fader library. It doesn't do what you think is does, I suspect. Fader.on() causes the led to fade up and then optionally fade down, up, down, up, down and so on for ever at the speed you request. Fader.off() just switches the led off. It does not fade down.

Is there still time to fix this before Santa visits your dad?