Go Down

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

secretreeve

Okay, here is the (almost) complete code!

It has all 3 sequences in there for the startup mode, impulse mode and warp mode.

Code: [Select]
// The Enterprise
// Author: Nick Gammon
// Date:   27 December 2012

#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,
  wantRCS,
  wantDeflectororangestartup,//                           startup mode
  wantDeflectororangeon,     // impulse mode
  wantDeflectorblueon,       //                 warp mode
  wantDeflectororangeoff,    //                 warp mode
  wantDeflectorblueoff,      // impulse mode
  wantNacellvioletstartup,   //                           startup mode
  wantNacellsvioleton,       // impulse mode
  wantNacellsblueon,         //                 warp mode
  wantNacellsvioletoff,      //                 warp mode
  wantNacellsblueoff,        // impulse mode
  wantImpulseredon,          // impulse mode
  wantImpulseorangeon,       //                 warp mode
  wantImpulseredoff,         //                 warp mode
  wantImpulseorangeoff,      // impulse mode
  wantImpulseorangestartup,   //                           startup mode
  wantShuttleBayon,          // impulse mode
  wantShuttleBaystartup,     //                            startup mode
  wantShuttleBayoff  ,       //                 warp mode
  wantNavigation,            // ALWAYS ON
  wantStrobes,               // ALWAYS ON
  wantTorpedoon,             // impulse 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);
  pinMode (NavigationPin, OUTPUT);

  // set up faders, flashers 
  impulseredFader.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 = wantTorpedoon;
         break;
         
    case wantTorpedoon:
         digitalWrite (TorpedoPin, HIGH);
             

         timeInThisState = 20000;         // no rush 10minutes, "600,000"
//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);
         
         timeInThisState = 20000;  //10 minutes, "600,000"
//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;
       
   case wantShuttleBayoff:
        digitalWrite(ShuttlebayPin, LOW);
   
   timeInThisState = 20000;     
         // 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


Problem is, theres a bug in the impulse lights (the 3rd and 4th from the right in the below video).

video: http://www.youtube.com/watch?v=f-trRl2oFaw&feature=youtu.be

As you can see, its not staying on when it is supposed to.  its the first blue led from the right. "impulseorange". It is MEANT to stay on until later on in the sequence when "impulsered" comes on and not turn off when the white one next to it comes on. Also i cant work out why the red (impulsered) is turning off as that is meant to stay on until the blue one (impulseorange) comes back on.

Can anyone see anything in the code which would cause it to be doing this?

Also, I still need a little more help in "down fading" the leds instead of them just "turning off" and getting impulse mode and warp mode to run in loops.

note: the led right in the middle at the lowest point is not meant to come on at any time. so thats not a problem.

secretreeve

So i guess I'll have to try and work this out.

Can someone tell me the output specs of the pins please? i.e voltage and current.

AWOL

Quote
Can someone tell me the output specs of the pins please? i.e voltage and current

HIGH voltage is supply minus a tiny bit, LOW is ground plus a tiny bit.
Current is an ABSOLUTE maximum of 40mA per pin, with a per-package limit of something like 200mA.

Or you could read the spec for your board.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

secretreeve

Well I would do if it had a specs sheet with in, but instead just had some legal stuff in it.

AWOL

I can't remember what board you're using, but if you follow the links here you should find the specs for whatever you have.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up