Go Down

Topic: Newbie needs assistance (Read 18 times) previous topic - next topic

Nick Gammon


Appreciated AWOL.

I dont suppose you have any ideas on the interaction between the torpedo pin (4) and the impulse pins? (3 and 5)


You don't have impulseorangeFader.begin() in setup.




Code: [Select]

   case wantTorpedoon:
         digitalWrite (TorpedoPin, HIGH);
             

         timeInThisState = 20000;         // no rush 10minutes, "600,000"


You don't have a "break" after this case, so it falls down to the next one. Ditto further down.

secretreeve



Appreciated AWOL.

I dont suppose you have any ideas on the interaction between the torpedo pin (4) and the impulse pins? (3 and 5)


You don't have impulseorangeFader.begin() in setup.




Code: [Select]

   case wantTorpedoon:
         digitalWrite (TorpedoPin, HIGH);
             

         timeInThisState = 20000;         // no rush 10minutes, "600,000"


You don't have a "break" after this case, so it falls down to the next one. Ditto further down.


I KNEW it was something simple. Yet to test it though. Just wanted to post and say thank you nick. I had entered the orangeFader.begin but forgot to post updated code. I've also cleaned house a bit too.

Time to test!

secretreeve

Heres the code now,

Looking pretty clean and working as it should be.

Now to work on down fading the leds instead of just turning off! WOOOOO progress!!!

I honestly cant believe how simple the fix was. Which is why i couldnt see it. i rarely see the simple solutions/repairs.

Code: [Select]
// The Enterprise

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

// pin assignments
const byte StrobesPin = 13;
const byte NavigationPin = 12;
const byte DeflectorbluePin = 11;   // PWM
const byte DeflectororangePin = 10;    // PWM
const byte NacellsbluePin = 9;      // PWM
const byte ShuttlebayPin = 8;
const byte DoorsPin = 7;
const byte NacellsvioletPin = 6;   // PWM
const byte ImpulseorangePin = 5;  // PWM
const byte TorpedoPin = 4;
const byte ImpulseredPin = 3;   // PWM
const byte RCSPin = 2;
const byte CabinPin = 1;

// Faders

//                                  pin           min   max   millis  on?    stop?
LedFader impulseredFader      (ImpulseredPin,      0,   40,  3000,   false,  true);
LedFader impulseorangeFader   (ImpulseorangePin,   0,   40,  3000,   false,  true);
LedFader deflectororangeFader (DeflectororangePin, 0,   40,  3000,   false,  true);
LedFader deflectorblueFader   (DeflectorbluePin,   0,   40,  3000,   false,  true);
LedFader nacellsvioletFader   (NacellsvioletPin,   0,   40,  3000,   false,  true);
LedFader nacellsblueFader     (NacellsbluePin,     0,   40,  3000,   false,  true);

// Flashers

//                        pin          off-time  on-time       on?
LedFlasher strobes    (StrobesPin,        8000,      100,     false);
LedFlasher navigation (NavigationPin,     2000,      500,     false);

// states for the state machine
typedef enum
  {
  initialState,
  wantCabin,                 // ALWAYS ON
  wantRCS,                   // ALWAYS ON
  wantNavigation,            // ALWAYS ON
  wantStrobes,               // ALWAYS ON
  wantTorpedostartup,        // ALWAYS ON 
  wantDeflectororangestartup,//                           startup mode
  wantNacellvioletstartup,   //                           startup mode
  wantShuttleBaystartup,     //                           startup mode
  wantImpulseorangestartup,  //                           startup mode
  wantDeflectororangeon,     // impulse mode
  wantDeflectorblueoff,      // impulse mode
  wantNacellsvioleton,       // impulse mode
  wantNacellsblueoff,        // impulse mode
  wantImpulseredon,          // impulse mode
  wantImpulseorangeoff,      // impulse mode
  wantShuttleBayon,          // impulse mode
  wantTorpedoon,             // impulse mode
  wantDeflectorblueon,       //                 warp mode
  wantDeflectororangeoff,    //                 warp mode
  wantNacellsblueon,         //                 warp mode
  wantNacellsvioletoff,      //                 warp mode
  wantImpulseorangeon,       //                 warp mode
  wantImpulseredoff,         //                 warp mode
  wantShuttleBayoff,         //                 warp mode
  wantTorpedooff,            //                 warp mode
 
  // more states here
 
  } states;

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

void setup ()
  {
  pinMode (CabinPin, OUTPUT);
  pinMode (RCSPin, OUTPUT);
  pinMode (ShuttlebayPin, OUTPUT);
  pinMode (NavigationPin, OUTPUT);
  pinMode (StrobesPin, OUTPUT);
  pinMode (TorpedoPin, OUTPUT);
 

  // set up faders, flashers 
  impulseorangeFader.begin ();
  impulseredFader.begin ();
  deflectororangeFader.begin ();
  deflectorblueFader.begin ();
  nacellsvioletFader.begin ();
  nacellsblueFader.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 = wantCabin;
         break;
         
    case wantCabin:
         digitalWrite (CabinPin, HIGH);
         state = wantRCS;
         break;
         
    case wantRCS:
         digitalWrite (RCSPin, HIGH);
         state = wantDeflectororangestartup;
         break;
         
    case wantDeflectororangestartup:
         deflectororangeFader.on();
         state = wantNacellvioletstartup;
         break;
         
    case wantNacellvioletstartup:
         nacellsvioletFader.on();
         state = wantImpulseorangestartup;
         break;
         
    case wantImpulseorangestartup:
         impulseorangeFader.on();
         state = wantShuttleBaystartup;
         break;
//doors open here         
    case wantShuttleBaystartup:
         digitalWrite (ShuttlebayPin, HIGH);
         state = wantStrobes;
         break;
         
    case wantStrobes:
         strobes.on();
         state = wantNavigation;
         break;
         
    case wantNavigation:
         navigation.on();
         state = wantTorpedostartup;
         break;
         
    case wantTorpedostartup:
         digitalWrite (TorpedoPin, HIGH);
         state = wantImpulseorangeoff;             
         timeInThisState = 5000;         // no rush
         break;
         
//impulse mode
    case wantImpulseorangeoff:
         impulseorangeFader.off();
         state = wantImpulseredon;
         break;
         
    case wantImpulseredon:
         impulseredFader.on();
         state = wantDeflectororangeon;
         break;
         
    case wantDeflectororangeon:
         deflectororangeFader.on();
         state = wantNacellsvioleton;
         break;
         
    case wantNacellsvioleton:
         nacellsvioletFader.on();
         state = wantShuttleBayon;
         break;
//doors need to open here         
    case wantShuttleBayon:
         digitalWrite (ShuttlebayPin, HIGH);
         state = wantTorpedoon;
         break;
         
    case wantTorpedoon:
         digitalWrite (TorpedoPin, HIGH);
         state = wantImpulseredoff;
         
         timeInThisState = 5000; 
         break;
         
//warp mode         
   case wantImpulseredoff:
        impulseredFader.off();
        state = wantImpulseorangeon;
        break;
       
   case wantImpulseorangeon:
        impulseorangeFader.on();
        state = wantDeflectororangeoff;
        break;
       
   case wantDeflectororangeoff:
        deflectororangeFader.off();
        state = wantDeflectorblueon;
        break;
       
   case wantDeflectorblueon:
        deflectorblueFader.on();
        state = wantNacellsvioletoff;
        break;
   
   case wantNacellsvioletoff:
        nacellsvioletFader.off();
        state = wantNacellsblueon;
        break;
       
   case wantNacellsblueon:
        nacellsblueFader.on();
        state = wantShuttleBayoff;
        break;
//doors need to close here       
   case wantShuttleBayoff:
        digitalWrite(ShuttlebayPin, LOW);
        state = wantTorpedooff;
        break;
       
   case wantTorpedooff:
        digitalWrite(TorpedoPin, LOW);
   
   timeInThisState = 5000;     
         // what next?
         break;
   
   
   }  // end of switch on state
   
  }  // end of doStateChange


void loop ()
  {
 
   if (millis () - lastStateChange >= timeInThisState)
     doStateChange ();

   // update faders, flashers
   impulseorangeFader.update ();
   impulseredFader.update ();
   deflectororangeFader.update ();
   deflectorblueFader.update ();
   nacellsvioletFader.update ();
   nacellsblueFader.update ();
   navigation.update ();
   strobes.update ();

  // other stuff here like testing switches
   
  }  // end of loop


secretreeve

Nick,

I know i've asked alot already, but could you possibly go into more detail about making the impulse mode statements and warp mode statements loop round indefinitely?

I've been googling around but havent come across anything helpful and not confusing.

Go Up