New Enterprise model ideas

Enterprise:

// pin assignments
const byte MainLightsPin = 13;
const byte StrobesPin = 12;   // PWM
const byte NavigationThrustersPin = 11;
const byte DeflectorBluePin = 10;   // PWM
const byte  DeflectorOrangePin= 9;    // PWM
const byte TorpedoPortPin = 8;
const byte TorpedoStarboardPin = 7;
const byte ImpulsePin = 6;   // PWM
const byte NavBeaconsPin = 5;   // PWM
const byte OuterWarpPin = 4; 
const byte WarpDrivePin = 3;  // PWM
const byte SpotLightsPin = 2; 

I believe I’ll have to add the below module for power to the strip LED’s I’m using for the warp drive and hull lighting

MAX7219

If I understood everything from this now closed thread found here:

But I’ve got a twist I want to use. I have a DSD TECH HM-10 Bluetooth 4.0 BLE that I want to add into the equation as well as 4 condition states I’d like to chose from:

All on (Default starting position): strobes flashing at correct rate, nav beacons, red, white and green flashing, blue deflector and sensor domes, hull lights, impulse thrusters on, warp drives on, except torpedos firing.

Impulse state: all lights off except hull lights on, strobe lights turn on, nav beacons turn on, spot lights turn on, nav thrusters fade on to full power, nav and sensor domes orange, impulse deck fades on to full power.

Warp drive state:

All states as above except: deflector and sensor domes fade from orange to blue, impulse fades off as warp drives fade on to full power.

Photons fire: at any independent state photons fade quickly up to full bright and immediately off from port, starboard, port, and starboard with a second delay between each shift.

Question now is this: would I need 4 separate sketches to achieve this or can I program a single sketch with those points added so when I either say impulse, warp drive, fire photons or all on, those events happen, or can I write my sketch with my parameters and then say the words to a paired echo device or tap on a Bluetooth app to act as switches?

And now I have found I don't have enough power to light everything. I Have A mix of standard led's for things like spot lights, nav beacons, but i have strip lights for standard lighting, the warp drives and impulse engines. I am using a mega 2530 board with an hm-10 Bluetooth module to send commands.

If you halve the brightness of the ledstrip, you save half the current and will still have quite bright lights.
In the dark it will be annoyingly bright...
You might want to reduce by a factor 1/4...

That is a good thought in that, especially as far as how bright the warp drive is, good idea, thank you. And as far as that goes, the spots are very bright and are I feel overpowered in the day time, in the dark i am sure those alone would be blinding.

And thank you for your assistance. I should have said that from the start.

To answer your original question:
Yes.
All states can be in one program.
The program can read your bluetooth receiver for a command.
Based on that command you can use a switch statement to go to the different states.
Write each state in a function.... that will help to structure the program.
Start with one state....
...add the others.
Then write a separate bluetooth receiver, that writes your commands to Serial. Then integrate everything together.
This will not be easy for a beginner...

No it is not, I am finding out over in the IO section of the forum. But I will find out and I will get it to do what I need to do. It’s just a matter of time. And I probably should prioritize what I need to do. Get the sketch fully scripted and the bugs out of it, and then figure out the hm-10 module to get it to connect to both echo dot and iPhone.

This is a little more complicated than I remember BASIC to be, that’s how long it’s been since I’ve had to write code, HTML not included.

This is my base coding that I still need to fix and change to meet the extra pins I added as well as defined.


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

// pin assignments

const byte StrobesPin = 12;   // PWM
const byte NavigationThrustersPin = 11;
const byte DeflectorBluePin = 10;   // PWM
const byte  DeflectorOrangePin= 9;    // PWM
const byte TorpedoPortPin = 8;
const byte TorpedoStarboardPin = 7;
const byte ImpulsePin = 6;   // PWM
const byte NavBeaconsPin = 5;   // PWM
const byte HullStripsPin= 4; 
const byte WarpDrivePin = 3;  // PWM
const byte SpotLightsPin = 2; 

// Faders                           pin           min  max  millis    on?    stop?
LedFader deflectororangeFader (DeflectororangePin, 0,   255,  3000,   false,  true);
LedFader deflectorblueFader   (DeflectorbluePin,   0,   255,  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.on();
         state = wantDeflectorblueon;
         timeInThisState = 4000;
         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.on();
         timeInThisState = 4000;
         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

I was just thinking to myself out loud this morning, and I think with using the MOSFETs to supply extra power for the strip lighting I am not going to be able to do the functions that I wanted to do. I don’t think I would be able to have the mega 2560 control the power through the mosfets, will I?

Why not?
Not sufficient pins?

No I think it was a more a case of limited thinking, lack of knowledge on how the MOSFETs actually work. Looking around it sounds like I can control the amount of voltage through the Arduino board that will operate the MOSFET like a dam and based on the amount of voltage going to the MOSFET board will control the amount of power going out from the MOSFET. As far as pins go, there’s 54 on a mega 2560(?), So pins output isn’t an issue, but the PWM’s may be, and if those become an issue, I can use the analogs and get the same results.

It just gets me back now to the same issue:

Anything I have connected to a mosfet is now on all the time without the arduino being on and the arduino does not seem to control anything connected by the mosfets. And there are no ground wires going to the high output side of the connected leds. It’s feels so much like driving around in circles.

So my understanding of how to connect the MOSFET is this:

Arduino pin 2 goes to trig/pwm, gnd goes to arduino ground(?), right side of MOSFET is positive and ground in from other source, left is to the positive of the LED and GRD pin on the arduino. I wired the enterprise so that there is a single ground wire, and then the pin wires i listed in my sketch, but could be way off base as I am still behind the learning curve and didn't get to this part in my digital electronics course for computer repairs. But ends in the lights not being controlled by the arduino, so not sure what I am doing wrong there either. I can plus in my 12 volt power supply and any LED set connected to a MOSFET in any way will be on.



Have you thought of using addressable LEDs like WS2812B or PL9823 for example? With only 1 pin you can control all the LEDs and you can program the color and brightness separately for each individual LED. You might not even need an Arduino Mega, just an Arduino Nano. With them you do not needed MOSFET, just only PSU with enough power.

1 Like

No, I did not, nor did I even know about those. But I am planning on lighting a Reliant kit, and that will certainly change my ideas on that now, thanks. And that just adds to the level of things that can be called, go to red alert and change all the interior lights to red for example, interesting ideas indeed. Thank you very much.

Those WS2812b’s look very handy for internal lighting, not too sure they will fit into the warp drives but certainly the body/structure would be great. And the strip lights I’ve got in the enterprise are just red for the impulse, blue for the warp drives and white for the hull and saucer sections. And they honestly do look much better than most anything else I’ve seen.


// 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,         900,       100,     false);
LedFlasher navigation (NavigationPin,      2900,      100,     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 = wantCabin;   // <------- move to earlier state
        break;
       
   case wantTorpedooff:
        digitalWrite(TorpedoPin, LOW);
   
   timeInThisState = 5000;    
   
   
   
   }  // 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

So I have found my code on a different section of the forum. I just need to tweak it to make it do more what I want. So now I’m left with the communication part, and some understanding. In the sketch, it has certain pins marked as PWM, but I’m looking around at some documentation I believe I have found where pins 12 through two are all PWM‘s for a mega 2560 is that correct? And can I use the HM Dash 10 and the ESP8266 boards together so that I have both Wi-Fi and Bluetooth or did I see that the ESP2866 boards have Wi-Fi and Bluetooth built-in?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.