Star Trek thingy

void loop()
{
// update lights
strobeLights.update ();
navLights.update ();
bussardA.update ();
bussardB.update ();
}

// SWITCH BETWEEN WARP MODE AND IMPULSE MODE
warpButtonState = digitalRead (warpButton); // check for button press
if (warpButtonState == High and stateChange == 0) { // if button has been pressed and state change between impulse/warp has not begun yet then:
stateChange = 1; // initialize state changeUse code tags to format code for the forum
fadeDown =1; // initialize fade down (dimmimng)
fadeUp = 0; // do not fade up yet (brightening)
}
error: 'warpButtonState' does not name a type
warpButtonState = digitalRead (warpButton); // check for button press
^~~~~~~~~~~~~~~

What am I missing here?

replace and with &&

Code tags and setup()..

have fun.. ~q

Why? They are alternative operators and generate the same assembly code.

I am, lol. it has been a while since I have done this. I am rewriting the original code to suit my needs for the model I am building, so except for the parts I am currently leaving out this code is rewritten verbatmum from the original working code, and kudos to Trevor for his efforts and diligence but even though it works it does have some issues which I am also trying to fix. now his code was written in the older version of arduino not the new version.

@cattledog sorry if i've offended you, seems like it,
only a snippet posted..
and honestly, quite busy, so not getting my full attention..
I apologize to the OP @bobhd3316 , I'm sure someone will be able to take care of you..

bye..~q

Oh and the warp button is designated as being pin 1 in the beginning of the in setup.

void loop() // The main program
{
// update lights
strobeLights.update ();
navLights.update ();
if (phaserState == 1) { // if phasers are active then update phaser flash
phaserLights.update ();
}
else {
digitalWrite (phaserPin, 0); // otherwise switch phasers off
}

// SWITCH BETWEEN WARP MODE AND IMPULSE MODE
warpButtonState = digitalRead (warpButton); // check for button press
if (warpButtonState == HIGH and stateChange == 0) { // if button has been pressed and state change between impulse/warp has not begun yet, then:
stateChange = 1; // initialize state change
fadeDown = 1; // initialize fade down (dimming)
fadeUp = 0; // do not fade up yet (brightening)
phaserState = 0; // turn off phaser effect
digitalWrite (phaserPin, LOW); // switch off phaser LED
}

This is the original code

Phasers and photon torpedoes will be the next part of his original code I will be rewriting and adding to this.

and then adding audio effects.

And, if possible, remove the push buttons in the original schematic and code with pin to pin coding to run the warp/impulse, phaser and photon torpedo effects.

Still no code tags or setup()

1 Like

//Navigation and Strobe light flashing
//Impulse/Warp Fade Effec//Bussard Lights Effect
//Author: Bob Davis
//Date: 19 June 2023

// LedFlasher by Nick Gammon, 23 Dec 2012
#include <LedFlasher.h>
#include <LedFlasher.h>

// set up LEDs
//Always-flashing LEDs: PIN  OFF  ON (milliseconds)
LedFlasher strobeLights (13, 1500, 150);
LedFlasher navLights (12, 1100, 100);
LedFlasher bussardA (A0-A3, 2, 10);
LedFlasher bussardB (A0-A3, 1, 10);

// set up the pin numbers used for warp mode avtivation/deactivation
 const int impulsePin = 11; // Pin 11 is a PWM pin, used to fade the red LED up and down
 const int warpPin = 10; // Pin 10 is a PWM pin, used to fade the blue warp LED up and down
 const int warpButton = 1; // Warpmode will be activated & deactivated by a button on pin 1

// set up variables used to activate/deactivate warp mode
  int fadeVal = 0; // variable for fade loop
  int fadeTime = 0; // variable for fade delay loop
  int fadeTo = 0; // variable for length of fade delay
  int maxFade = 255; // set max brightness value for fade-up and fade-down
  int warpMode = 1; // Warp mode: 0 = impulse; 1 = warp
  int warpButtonState = 0; // flag to check if button has been pressed
  int stateChange = 0; // flag to prevent reading button on pin 1 during warp LEDs fade-in & fade-out
  int fadeLenght =3000; // approximate lenght of time (milliseconds) in which the fade-down fade-up cycle will take place
  int fadeDown = 0; // flag to check if we are currently fading down to 0
  int fadeUp = 0; // flag to check if we are currently fading up to 255

void setup()
 {
  strobeLights.begin ();
  navLights.begin ();
  bussardA.begin ();

 pinMode (impulsePin, OUTPUT); // Impulse LED on pin 11
 pinMode (warpPin, OUTPUT); // Warp LED on pin 10
 pinMode (warpButton, INPUT); // Warp mode button on pin 1

 // small delay before fade-up of red impulse mode LED
   for (int deLay1 = 0; deLay1 <= 40; deLay1 +=1) {
     for (int deLay2 = 0; deLay2 <5000; deLay2 +=1) {
       strobeLights.update ();
       navLights.update ();
       bussardA.update ();
     }
   } // end small delay on startup

   // fade-up red or blue impulse mode LED at startup
     for (fadeVal = 0; fadeVal <= maxFade; fadeVal +=1) {
       if (warpMode = 0) {
         analogWrite (impulsePin, fadeVal);
       }
       else {
         analogWrite (warpPin, fadeVal);
       }
       strobeLights.update ();
       navLights.update ();
       bussardA.update ();
     }
    }
  
 // end of setup
    
void loop() 
 {
  // update lights
  strobeLights.update ();
  navLights.update ();
  bussardA.update ();
  bussardB.update ();
  const int warpButton = 1;
  } 

 // SWITCH BETWEEN WARP MODE AND IMPULSE MODE
 int WarpButtonState = digitalRead (warpButton); // check for button press
  int If (warpButtonState == 1 and stateChange == 0);  // if button has been pressed and state change between impulse/warp has not begun yet then:
  int StateChange = 1; // initialize state change
  int FadeDown =1; // initialize fade down (dimmimng)
  int FadeUp = 0; // do not fade up yet (brightening)
  

 
 // IMPULSE TO WARP - Fade orange to black first
 {
   int If (11 == 0 and stateChange ==1 and fadeDown == 1); 
     for (fadeVal = maxFade; fadeVal >= 0; fadeVal -=1);
      analogWrite (impulsePin, fadeVal);
      for (fadeTime = 0; fadeTime <= fadeTo; fadeTime +=1);
        strobeLights.update ();
        navLights.update ();
        bussardA.update ();
      
   
   fadeDown = 0;
   fadeUp = 1;
 
 // IMPULSE TO WARP - Fade black to blue
 if (warpMode == 0 and stateChange == 1 and fadeUp == 1) {
   for (fadeVal = 0; fadeVal <= maxFade; fadeVal +=1) {
     analogWrite (warpPin, fadeVal);
     for (fadeTime = 0; fadeTime <= fadeTo; fadeTime +=1) {
       strobeLights.update ();
       navLights.update ();
       bussardB.update ();
      }
   }
   fadeUp = 0;
   stateChange = 0;
   warpMode = 1;
 }

 // SWITCH BETWEEN IMPULSE MODE AND WARP MODE
 // button state was checked above; state change and fade down were activated

  // WARP TO IMPULSE - Fade blue to black first
  if (warpMode == 1 and stateChange == 1 and fadeDown == 1) {
    for (fadeVal = maxFade; fadeVal >= 0; fadeVal -=1) {
      analogWrite (warpPin, fadeVal);
      for ( fadeTime = 0; fadeTime <= fgadeTo; fadeTime += 1) {
        strobeLights.update ();
        navLights.update ();
        bussardB.update ();
      }
    }
    fadeDown = 0;
    fadeUp = 1;
  }
  // WARP TO IMPULSE - Fade black to red
  if (warpMode == 1 and stateChange == 1 and fadeUp ==1) {
    for (fadeVal = 0; fadeVal <= maxFade; fadeVal += 1) {
      analogWrite (impulsePin, fadeVal);
      for (fadeTime = 0; fadeTime <= fadeTo; fadeTime += 1){
        strobeLights.update ();
        navLights.update ();
        bussardA.update ();
      }
    }
    fadeUp = 0;
    stateChange = 0;
    warpMode = 0;
  } // end of loop

C:\Users\bobhd\OneDrive\Documents\Arduino\sketch_jun18a_copy_20230623162632_copy_20230623164001\sketch_jun18a_copy_20230623162632_copy_20230623164001.ino:90:2: error: expected unqualified-id before '{' token
{
^

exit status 1

Compilation error: expected unqualified-id before '{' token

OK, so this is the entire sketch as written so far, you guys keep telling its missing code tags and setup but thats not very helpful. You really need be more specific.

The code in your original post has executable statements outside of any function block.

You can pretty much only have declarations outside of a function body. Therefore a line like this:

warpButtonState = digitalRead (warpButton); // check for button press

Is expected to be a variable declaration. A variable declaration requires a type. You did not specify a known type and thus you get the "does not name a type" error.

My guess is that that line of code and the ones that follow it should be part of a function body, but not sure whether you intend it to be part of loop or some other function whose declaration is missing.

I hope that helps.

@Delta_G and @gm310509 that is very helpful compared to everyone else's answers and here is why....
I am currently working off of someone else's sketches trying to correct some issues I have come across with it (even though it does work) and rewrite it to match my particular models requirements. Some of his coding has written verbatum while leaving out aspects I do not need at this point and adding some of my own coding that was not in his (for a different model) so it goes without saying that there might be some issues, and both of you actually addressed them instead of giving me some generic answer.
I am adding each effect as a process to try and work out the issues I found with Trevor's sketch and expect to run into some of the same issues which I will deal as they come up to try and correct them, a short example is that strobe lights change once an effect is activated and never returns their normal state as is the same case with the navigation lights.
I have done a lot of switching brackets and braces around and have ended up with different results. This particular change has been the best result i have gotten ending in much fewer errors.
I have three more effects to add and I am sure I will have some issues as I add them. The next effect I intend to add is Phasers, then photon torpedoes. and finally audio and timing.

The last and final thing I want to do is remove the push button activation of the effects and change them to digital pin to pin activation using code to activate the effects. I will be taking measurements and readings to determine how best to do this. Now I just have to take a closer look at everything.

Did you see anything wrong with setup?

anything wrong with setup?

You probably want to have brussardB.begin();

LedFlasher bussardA (A0-A3, 2, 10);
LedFlasher bussardB (A0-A3, 1, 10);

These constructors don't look correct. I don't see how A0-A3 works as a const byte pin number.

LedFlasher::LedFlasher (const byte pin, const unsigned long timeOff, const unsigned long timeOn, const bool active)

Can you explain a little further ? It actually did in the previous sketch. now I am adding to the sketch and bussardA is actually intended to run first as this is impulse mode and is meant to run slower while bussardB is faster and meant to run in warp mode, or did i switch them by accident?

OK, so here is the premise, pins 1,2 and 4 control switching between the impulse/warp mode, firing phasers and photon torpedoes--pin 1 is engine mode. I am using an arduino uno rev.3. The initial sketch works but with issues, and I understand what you are saying about pin 1. However that could be part of the issues with how the effects are changing and I have considered that. Once I push any button to activate an effect the timing on the strode and nav lights change from the how they are to alternating.