Go Down

Topic: Newbie needs assistance (Read 19477 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.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

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

http://www.youtube.com/watch?v=HFTBOWlIVBg&list=PL1ja0k2ccCfverSOdZQo0rclB5YKm89W7&index=6

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.

Nick Gammon

Googling won't necessarily help. I tried to explain in reply #240.

Can you describe in what way that reply does not address the issue for you?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

secretreeve

#261
Dec 31, 2012, 09:17 pm Last Edit: Dec 31, 2012, 09:24 pm by secretreeve Reason: 1
Well i have no idea on how to tell the code to return to X point in the list of cases once it reaches the end of the code and to repeat that action continuously.

okay, now i have both hands free. Was eating haha.

Basically i dont know the code line to return to a certain possition, and i dont know how you could define that position. Does each case statement end up with it being numbered automatically or what?

I guess i need help on this because of not knowing the command lines to do it and im also looking to understand how the process works as well.

Nick Gammon

You have to try to understand the code. Seriously.

I don't know how else to explain it. Perhaps someone else can do a better job than me.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

secretreeve

Well the thing is, i dont know what the code is to make it loop.

"go back to 1" isnt really the code to say go back to 1.

I dont know what code to put in to make it go back to X place in the code.

I know what your trying to say, but i dont have the command lines to make it "go back to X place" anyway, so even if i did understand it i wouldnt be able to use it because i dont have that line(s)

AWOL

"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

#265
Dec 31, 2012, 09:36 pm Last Edit: Dec 31, 2012, 09:42 pm by secretreeve Reason: 1
oh come on!

how can i get it when i dont know the line that makes it do something?

It feels like being asked to play the oveture on the piano without the sheet music and having never played it before.

I need the sheet music to use the piano and play the piece.

the sheet music being the missing key.

Nick Gammon

Look, each state "moves on" to the next one, eg.

Code: [Select]

    case wantCabin:
         digitalWrite (CabinPin, HIGH);
         state = wantRCS;   // <----------- change state here
         break;


To "go backwards" you simply move to an earlier state, eg.

Code: [Select]

   case wantShuttleBayoff:
        digitalWrite(ShuttlebayPin, LOW);
        state = wantCabin;   // <------- move to earlier state
        break;


That's it!

Or in loop you might do that.

Code: [Select]

if (buttonPressed)
  state = wantCabin;


Understand the state machine and this will be obvious. It's just lines of code, it's not magic.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

AWOL

Quote
how can i get it when i dont know the line that makes it do something?
Like I said, a little less argument and a bit more application.

You've started to learn French with "un petit d'un petit", and straight away gone on to "A la recerche du temps perdus".
"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

OHHHH.

No, i thought the "return to X point" would be more complicated.

Okay, well i have it looping now, just need to get the warp leds to turn off in impulse mode. easily done.

Thanks. I was thinking overly complicated.

Go Up