Pages: 1 ... 15 16 [17] 18   Go Down
Author Topic: Newbie needs assistance  (Read 13207 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The only other thing is I'm getting errors because of duplicate uses. Is there an easy way around that without having lists of defines and so on longer than the operating code?

What do you mean by defines? My code didn't have a single one, so I don't see where "lists of defines" comes from.

Nick what did you mean about the state 50 and so on?

If you have 50 states the next state doesn't have to be the 51st. one. States can loop.

For example, if your daily routine is:

  • 1. Wake up
  • 2. Get out of bed
  • 3. Have breakfast
  • 4. Go to work
  • 5. Have dinner
  • 6. Go to bed
  • 7. Go to state 1.

The 7th state in my example "goes backwards" (loops) so next day you do the same thing.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 174
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

wantimpulsered

if used more than once, would return a duplication error when called for twice, once to turn on and once to turn off. obviously at different stages in the "list of events"
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Time for you to start thinking about this. You need two states, right? One to turn impulsered on, and one to turn impulsered off. Any ideas for their names?
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 174
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had tried that, But for some reason the newer entry looped the fade.

I'll take another look at it tomorow though and see what happens.

Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 174
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The only other thing is, I know you said about the states, but still not sure on "down fading".

Also, the "startup sequence" stage is knocked out, so for the impulse mode sequence, would i want to put that where the note says //what next?

or after the break;

I'm thinking it would be where "whats next?" is. but just want to get that confirmed.

Also, progress report with code!

Code:
// 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,
  wantDeflectororangeon,     // impulse mode
  wantDeflectorblueon,       //                 warp mode
  wantDeflectororangeoff,    //                 warp mode
  wantDeflectorblueoff,      // impulse 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
  wantShuttleBayopen         // open in impulse
  wantShuttleBayclosed       //                 closed in warp
  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 = wantDeflectororangeon;
         break;
         
    case wantDeflectororangeon:
         deflectororangeFader.on ();
         state = wantDeflectorblueon;
         break;
         
    case wantDeflectorblueon:
         deflectorblueFader.off();
         state = wantNacellsvioleton;
         break;
         
    case wantNacellsvioleton:
         nacellsvioletFader.on();
         state = wantImpulseorangeon;
         break;
         
    case wantImpulseorangeon:
         impulseorangeFader.on();
         state = wantShuttleBay;
         break;
         
    case wantShuttleBay:
         digitalWrite (ShuttlebayPin, HIGH);
         state = wantStrobes;
         break;
         
        case wantStrobes:
         strobes.on();
         state = wantNavigation;
         break;
         
    case wantNavigation:
         navigation.on();
         state = wantTorpedo;
         break;
         
    case wantTorpedo:
         digitalWrite (TorpedoPin, HIGH);
             

         timeInThisState = 5000;         // no rush

         // 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

The notes in the want list are there to help me keep organised, so pay them little mind.
« Last Edit: December 28, 2012, 06:51:34 pm by secretreeve » Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 174
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay, here is the (almost) complete code!

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

Code:
// 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.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 174
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24449
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Offline Offline
Full Member
***
Karma: 0
Posts: 174
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24449
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

"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.

Offline Offline
Full Member
***
Karma: 0
Posts: 174
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks AWOL. Its the UNO i think. It's got uno printed on it anyway lol.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24449
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've deleted four or five off-topic, pointless recent replies to this thread.
Please, you know who you are - just don't.
Logged

"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.

Offline Offline
Full Member
***
Karma: 0
Posts: 174
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Appreciated AWOL.

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

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24449
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, I'm afraid I don't and short of building your hardware, I don't suppose I'll be finding out any time soon.
Logged

"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.

Offline Offline
Full Member
***
Karma: 0
Posts: 174
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well it was worth asking.
Logged

Pages: 1 ... 15 16 [17] 18   Go Up
Jump to: