button/bluetooth combo

Hello, I’ve been programming for a while but this is stumped me. I want to control some relays via bluetooth, this i have working but i want to use a single push button with multiple purposes (this i also have working in a septate sketch) but when i combine the two it always stops the bluetooth from working. any ideas?

Heres the bluetooth code:

char inData[50];
char inChar=-1;
byte index = 0;
int ledpin = 13;  

void setup() 
{

 pinMode(ledpin = 2, OUTPUT); // ACC pin
 pinMode(ledpin = 3, OUTPUT); // ON pin
 pinMode(ledpin = 4, OUTPUT); // START pin
 pinMode(ledpin = 5, OUTPUT); // LOCK
 pinMode(ledpin = 5, OUTPUT); // UNLOCK
 pinMode(ledpin = 7, OUTPUT); // WINDOW N/S/F UP
 pinMode(ledpin = 8, OUTPUT); // WINDOW N/S/F DOWN
 pinMode(ledpin = 9, OUTPUT); // WINDOW O/S/F UP
 pinMode(ledpin = 10, OUTPUT); // WINDOW O/S/F DOWN

  digitalWrite(ledpin = 2, HIGH);
  digitalWrite(ledpin = 3, HIGH);
  digitalWrite(ledpin = 4, HIGH);
  digitalWrite(ledpin = 5, HIGH);
  digitalWrite(ledpin = 6, HIGH);
  digitalWrite(ledpin = 7, HIGH);
  digitalWrite(ledpin = 8, HIGH);
  digitalWrite(ledpin = 9, HIGH);
  digitalWrite(ledpin = 10, HIGH);

Serial.begin(38400);

} 
  



char Comp(char* This) {
   while (Serial.available() > 0) 
   {
       if(index < 49) 
       {
           inChar = Serial.read(); 
           inData[index] = inChar; 
           index++; 
           inData[index] = '\0'; 
       }
   }

   if (strcmp(inData,This)  == 0) {
       for (int i=0;i<49;i++) {
           inData[i]=0;
       }
       index=0;
       return(0);
   }
   else {
       return(1);
   }
}

void loop()

{
 if( Serial.available() )       
 {
 }        


 if(Comp("start engine")==0) {
  digitalWrite(ledpin = 2, HIGH);
  digitalWrite(ledpin = 3, HIGH);
  delay(1000);
   digitalWrite(ledpin = 2, LOW);    
   digitalWrite(ledpin = 3, LOW);    
   delay(2000);
   digitalWrite(ledpin = 4, LOW);  
   delay(1000);                     
   digitalWrite(ledpin = 4, HIGH);    
 }
 
 if(Comp("stop engine")==0) {
   digitalWrite(ledpin = 2, HIGH);  
   digitalWrite(ledpin = 3, HIGH); 
 }

 if(Comp("ignition on")==0) {
   digitalWrite(ledpin = 2, LOW);    
   digitalWrite(ledpin = 3, LOW);   
 }
 if(Comp("ignition off")==0) {             
    digitalWrite(ledpin = 2, HIGH);  
    digitalWrite(ledpin = 3, HIGH);  
 }
 if(Comp("lock")==0) {             ;
   digitalWrite(ledpin = 5, LOW);
   delay(500);
   digitalWrite(ledpin = 5, HIGH);
 }
 if(Comp("unlock")==0) {
   digitalWrite(ledpin = 5, LOW);
   delay(500);
   digitalWrite(ledpin = 5, HIGH);  
 }
 if(Comp("reset")==0) {              
 
   digitalWrite(ledpin = 2, HIGH);  
   digitalWrite(ledpin = 3, HIGH);  
   digitalWrite(ledpin = 4, HIGH);  
   digitalWrite(ledpin = 5, HIGH);  
 }
 if(Comp("passenger window front up")==0) {              
 
   digitalWrite(ledpin = 7, LOW);
   delay(15000); 
   digitalWrite(ledpin = 7, HIGH);
 }
 if(Comp("passenger window front down")==0) {              
 
   digitalWrite(ledpin = 8, LOW);
   delay(15000); 
   digitalWrite(ledpin = 8, HIGH);
 }
 if(Comp("drivers window front up")==0) {              
 
   digitalWrite(ledpin = 9, LOW);
   delay(15000); 
   digitalWrite(ledpin = 9, HIGH);
 }
 if(Comp("drivers window front down")==0) {              
 
   digitalWrite(ledpin = 10, LOW);
   delay(15000); 
   digitalWrite(ledpin = 10, HIGH);   
 } 
 if(Comp("warm up")==0) {
  digitalWrite(ledpin = 2, HIGH);
  digitalWrite(ledpin = 3, HIGH);
  delay(1000);
   digitalWrite(ledpin = 2, LOW);    
   digitalWrite(ledpin = 3, LOW);    
   delay(2000);
   digitalWrite(ledpin = 4, LOW);  
   delay(1000);                     
   digitalWrite(ledpin = 4, HIGH);
   delay(900000);
   digitalWrite(ledpin = 2, HIGH);
   digitalWrite(ledpin = 3, HIGH);
 }
 if(Comp("cool down")==0) {
   digitalWrite(ledpin = 8, LOW);
   delay(15000); 
   digitalWrite(ledpin = 8, HIGH);
   digitalWrite(ledpin = 10, LOW);
   delay(15000); 
   digitalWrite(ledpin = 10, HIGH);   
   delay(900000);
   digitalWrite(ledpin = 7, LOW);
   delay(15000); 
   digitalWrite(ledpin = 7, HIGH);
   digitalWrite(ledpin = 9, LOW);
   delay(15000); 
   digitalWrite(ledpin = 9, HIGH);
 }
}

and here is the button code:

const int button = 12;
const int led = 13;

int bounceTime = 50;
int holdTime = 2000;
int doubleTime = 700;

int lastReading = LOW;
int hold = 0;
int single = 0;
int LEDstate = 0;

long onTime = 0;
long lastSwitchTime = 0;


void setup() {
pinMode(button, INPUT);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
Serial.begin(38400);
}

void loop() {

int reading = digitalRead(button);

//first pressed
if (reading == HIGH && lastReading == LOW) {
  onTime = millis();
}

//held
if (reading == HIGH && lastReading == HIGH) {
  if ((millis() - onTime) > holdTime) {
    invertLED();  
    hold = 1;
  }
}

//released
if (reading == LOW && lastReading == HIGH) {
  if (((millis() - onTime) > bounceTime) && hold != 1) {
    onRelease();
  }
  if (hold == 1) {
  digitalWrite(ledpin = 2, HIGH);
  digitalWrite(ledpin = 3, HIGH);
  delay(1000);
   digitalWrite(ledpin = 2, LOW);    
   digitalWrite(ledpin = 3, LOW);    
   delay(2000);
   digitalWrite(ledpin = 4, LOW);  
   delay(1000);                     
   digitalWrite(ledpin = 4, HIGH);    
    hold = 0;
  }   
}
lastReading = reading;

if (single == 1 && (millis() - lastSwitchTime) > doubleTime) {
   digitalWrite(ledpin = 2, HIGH);  
   digitalWrite(ledpin = 3, HIGH); 
  single = 0;
}

}


void onRelease() {

if ((millis() - lastSwitchTime) >= doubleTime) {
  single = 1;
  lastSwitchTime = millis();
  return;
}  

if ((millis() - lastSwitchTime) < doubleTime) {
  toggleLED();
   digitalWrite(ledpin = 2, LOW);    
   digitalWrite(ledpin = 3, LOW);   
  single = 0;
  lastSwitchTime = millis();
}  
}

void toggleLED() {
if (LEDstate == 0) {
  LEDstate = 1;
} else {
  LEDstate = 0;
}
digitalWrite(led, LEDstate);  
} 

void invertLED() {
if (LEDstate == 0) {
digitalWrite(led, 1);
} else {
digitalWrite(led, 0);
}
}





int reading = digitalRead(button);

 lastReading = reading;

again the button always cancel’s out the bluetooth

Thanks for your help

You posted two working codes, incorrectly. You did not post the nonworking code. How can you realistically expect us to know what you did wrong?

Read the stickies at the top of the forum BEFORE you post any more code.

sorry this is the code i tried (no errors):

const int button = 12;
const int led = 13;

int bounceTime = 50;
int holdTime = 2000;
int doubleTime = 700;

int lastReading = LOW;
int hold = 0;
int single = 0;
int LEDstate = 0;

long onTime = 0;
long lastSwitchTime = 0;

char inData[50];
char inChar=-1;
byte index = 0;
int ledpin = 13;  


void setup() {
pinMode(button, INPUT);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
Serial.begin(38400);


{
 pinMode(ledpin = 2, OUTPUT); // ACC pin
 pinMode(ledpin = 3, OUTPUT); // ON pin
 pinMode(ledpin = 4, OUTPUT); // START pin
 pinMode(ledpin = 5, OUTPUT); // LOCK
 pinMode(ledpin = 5, OUTPUT); // UNLOCK
 pinMode(ledpin = 7, OUTPUT); // WINDOW N/S/F UP
 pinMode(ledpin = 8, OUTPUT); // WINDOW N/S/F DOWN
 pinMode(ledpin = 9, OUTPUT); // WINDOW O/S/F UP
 pinMode(ledpin = 10, OUTPUT); // WINDOW O/S/F DOWN

  digitalWrite(ledpin = 2, HIGH);
  digitalWrite(ledpin = 3, HIGH);
  digitalWrite(ledpin = 4, HIGH);
  digitalWrite(ledpin = 5, HIGH);
  digitalWrite(ledpin = 6, HIGH);
  digitalWrite(ledpin = 7, HIGH);
  digitalWrite(ledpin = 8, HIGH);
  digitalWrite(ledpin = 9, HIGH);
  digitalWrite(ledpin = 10, HIGH);



} 
}
char Comp(char* This) {
   while (Serial.available() > 0) 
   {
       if(index < 49) 
       {
           inChar = Serial.read(); 
           inData[index] = inChar; 
           index++; 
           inData[index] = '\0'; 
       }
   }

   if (strcmp(inData,This)  == 0) {
       for (int i=0;i<49;i++) {
           inData[i]=0;
       }
       index=0;
       return(0);
   }
   else {
       return(1);
   }
}
void loop() {

int reading = digitalRead(button);

//first pressed
if (reading == HIGH && lastReading == LOW) {
  onTime = millis();
}

//held
if (reading == HIGH && lastReading == HIGH) {
  if ((millis() - onTime) > holdTime) {
    invertLED();  
    hold = 1;
  }
}

//released
if (reading == LOW && lastReading == HIGH) {
  if (((millis() - onTime) > bounceTime) && hold != 1) {
    onRelease();
  }
  if (hold == 1) {
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  delay(1000);
   digitalWrite(2, LOW);    
   digitalWrite(3, LOW);    
   delay(2000);
   digitalWrite(4, LOW);  
   delay(1000);                     
   digitalWrite(4, HIGH);    
    hold = 0;
  }   
}
lastReading = reading;

if (single == 1 && (millis() - lastSwitchTime) > doubleTime) {
   digitalWrite(2, HIGH);  
   digitalWrite(3, HIGH); 
  single = 0;
}

}


void onRelease() {

if ((millis() - lastSwitchTime) >= doubleTime) {
  single = 1;
  lastSwitchTime = millis();
  return;
}  

if ((millis() - lastSwitchTime) < doubleTime) {
  toggleLED();
   digitalWrite(2, LOW);    
   digitalWrite(3, LOW);   
  single = 0;
  lastSwitchTime = millis();
}  
}

void toggleLED() {
if (LEDstate == 0) {
  LEDstate = 1;
} else {
  LEDstate = 0;
}
digitalWrite(led, LEDstate);  
} 

void invertLED() {
if (LEDstate == 0) {
digitalWrite(led, 1);
} else {
digitalWrite(led, 0);
}
{
 if( Serial.available() )       
 {
 }        


 if(Comp("start engine")==0) {
  digitalWrite(ledpin = 2, HIGH);
  digitalWrite(ledpin = 3, HIGH);
  delay(1000);
   digitalWrite(ledpin = 2, LOW);    
   digitalWrite(ledpin = 3, LOW);    
   delay(2000);
   digitalWrite(ledpin = 4, LOW);  
   delay(1000);                     
   digitalWrite(ledpin = 4, HIGH);    
 }
 
 if(Comp("stop engine")==0) {
   digitalWrite(ledpin = 2, HIGH);  
   digitalWrite(ledpin = 3, HIGH); 
 }

 if(Comp("ignition on")==0) {
   digitalWrite(ledpin = 2, LOW);    
   digitalWrite(ledpin = 3, LOW);   
 }
 if(Comp("ignition off")==0) {             
    digitalWrite(ledpin = 2, HIGH);  
    digitalWrite(ledpin = 3, HIGH);  
 }
 if(Comp("lock")==0) {             ;
   digitalWrite(ledpin = 5, LOW);
   delay(500);
   digitalWrite(ledpin = 5, HIGH);
 }
 if(Comp("unlock")==0) {
   digitalWrite(ledpin = 5, LOW);
   delay(500);
   digitalWrite(ledpin = 5, HIGH);  
 }
 if(Comp("reset")==0) {              
 
   digitalWrite(ledpin = 2, HIGH);  
   digitalWrite(ledpin = 3, HIGH);  
   digitalWrite(ledpin = 4, HIGH);  
   digitalWrite(ledpin = 5, HIGH);  
 }
 if(Comp("passenger window front up")==0) {              
 
   digitalWrite(ledpin = 7, LOW);
   delay(15000); 
   digitalWrite(ledpin = 7, HIGH);
 }
 if(Comp("passenger window front down")==0) {              
 
   digitalWrite(ledpin = 8, LOW);
   delay(15000); 
   digitalWrite(ledpin = 8, HIGH);
 }
 if(Comp("drivers window front up")==0) {              
 
   digitalWrite(ledpin = 9, LOW);
   delay(15000); 
   digitalWrite(ledpin = 9, HIGH);
 }
 if(Comp("drivers window front down")==0) {              
 
   digitalWrite(ledpin = 10, LOW);
   delay(15000); 
   digitalWrite(ledpin = 10, HIGH);   
 } 
 if(Comp("warm up")==0) {
  digitalWrite(ledpin = 2, HIGH);
  digitalWrite(ledpin = 3, HIGH);
  delay(1000);
   digitalWrite(ledpin = 2, LOW);    
   digitalWrite(ledpin = 3, LOW);    
   delay(2000);
   digitalWrite(ledpin = 4, LOW);  
   delay(1000);                     
   digitalWrite(ledpin = 4, HIGH);
   delay(900000);
   digitalWrite(ledpin = 2, HIGH);
   digitalWrite(ledpin = 3, HIGH);
 }
 if(Comp("cool down")==0) {
   digitalWrite(ledpin = 8, LOW);
   delay(15000); 
   digitalWrite(ledpin = 8, HIGH);
   digitalWrite(ledpin = 10, LOW);
   delay(15000); 
   digitalWrite(ledpin = 10, HIGH);   
   delay(900000);
   digitalWrite(ledpin = 7, LOW);
   delay(15000); 
   digitalWrite(ledpin = 7, HIGH);
   digitalWrite(ledpin = 9, LOW);
   delay(15000); 
   digitalWrite(ledpin = 9, HIGH);
 }
}
}
{
 pinMode(ledpin = 2, OUTPUT); // ACC pin
 pinMode(ledpin = 3, OUTPUT); // ON pin
 pinMode(ledpin = 4, OUTPUT); // START pin
 pinMode(ledpin = 5, OUTPUT); // LOCK
 pinMode(ledpin = 5, OUTPUT); // UNLOCK
 pinMode(ledpin = 7, OUTPUT); // WINDOW N/S/F UP
 pinMode(ledpin = 8, OUTPUT); // WINDOW N/S/F DOWN
 pinMode(ledpin = 9, OUTPUT); // WINDOW O/S/F UP
 pinMode(ledpin = 10, OUTPUT); // WINDOW O/S/F DOWN

  digitalWrite(ledpin = 2, HIGH);
  digitalWrite(ledpin = 3, HIGH);
  digitalWrite(ledpin = 4, HIGH);
  digitalWrite(ledpin = 5, HIGH);
  digitalWrite(ledpin = 6, HIGH);
  digitalWrite(ledpin = 7, HIGH);
  digitalWrite(ledpin = 8, HIGH);
  digitalWrite(ledpin = 9, HIGH);
  digitalWrite(ledpin = 10, HIGH);



}

What are the curly braces for? Have you seen another example that looks like this? Get rid of the ledpin = bit from all of those statements.

{
 if( Serial.available() )      
 {
 }

More useless curly braces. If there is serial data to read, do nothing. Otherwise, do nothing. Why bother testing whether you need to do nothing, when you are going to do it anyway?

Under what circumstances do you actually read serial data? That happens only in Comp(), which is called only by invertLED(), which is called only when the state of the LED needs to change.

To me, that logic is completely wrong. I would be reading all pending serial data on EVERY pass through loop(), and I would be comparing what I read only when I received an end-of-packet marker.

Independent of reading serial data, and setting state based on what I read, I would be determining if it was time to do something else, based on time and state.

the serial need to be constant as its used as remote car lock and unlock and remote systems, so that needs to run all the time. what i need is the button to run what the bluetooth does. for example: start the car via bluetooth > drive somewhere > turn engine off via button. another example is, get in car want to turn ignition on but not start (again double press the button to do that).

so basically want to start/stop engine via BT and button. or ignition on/off via BT and button

the serial need to be constant as its used as remote car lock and unlock and remote systems, so that needs to run all the time.

This is nonsense. If the serial data were constant, there would be no reason to read it.

You are going about reading serial data all wrong. Until you see that, there is no point in trying to fix the code.

I'm confused, I've never done this before so if people arn't willing to help then what's the point in this form and what's the point in trying if no help will be given

right after some hours, ive finally got it working but not totally sure how, here is the working code:

const int button = A0;
const int led = 13;
int bounceTime = 50;
int holdTime = 1500;
int doubleTime = 1000;
int lastReading = LOW;
int hold = 0;
int single = 0;
int LEDstate = 0;
long onTime = 0;
long lastSwitchTime = 0;
int incomingByte = 0;
int ledpin = 13;  
char inData[50]; // Allocate some space for the string
char inChar=-1; // Where to store the character read
byte index = 0; // Index into array; where to store the character

void setup() {
pinMode(button, INPUT);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);



{
 pinMode(2, OUTPUT); // ACC pin
 pinMode(3, OUTPUT); // ON pin
 pinMode(4, OUTPUT); // START pin
 pinMode(5, OUTPUT); // LOCK
 pinMode(5, OUTPUT); // UNLOCK
 pinMode(7, OUTPUT); // WINDOW N/S/F UP
 pinMode(8, OUTPUT); // WINDOW N/S/F DOWN
 pinMode(9, OUTPUT); // WINDOW O/S/F UP
 pinMode(10, OUTPUT); // WINDOW O/S/F DOWN

  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);
  digitalWrite(10, HIGH);
  Serial.begin(38400);

}
}
char Comp(char* This) {
    while (Serial.available() > 0) // Don't read unless
                                   // there you know there is data
    {
        if(index < 49) // One less than the size of the array
        {
            inChar = Serial.read(); // Read a character
            inData[index] = inChar; // Store it
            index++; // Increment where to write next
            inData[index] = '\0'; // Null terminate the string
        }
    }

    if (strcmp(inData,This)  == 0) {
        for (int i=0;i<49;i++) {
            inData[i]=0;
        }
        index=0;
        return(0);
    }
    else {
        return(1);
    }
}
   

void loop()
{
 if(Comp("start engine")==0) {
  digitalWrite(ledpin = 2, HIGH);
  digitalWrite(ledpin = 3, HIGH);
  delay(1000);
   digitalWrite(ledpin = 2, LOW);    
   digitalWrite(ledpin = 3, LOW);    
   delay(2000);
   digitalWrite(ledpin = 4, LOW);  
   delay(1000);                     
   digitalWrite(ledpin = 4, HIGH);    
 }
 
 if(Comp("stop engine")==0) {
   digitalWrite(ledpin = 2, HIGH);  
   digitalWrite(ledpin = 3, HIGH); 
 }

 if(Comp("ignition on")==0) {
   digitalWrite(ledpin = 2, LOW);    
   digitalWrite(ledpin = 3, LOW);   
 }
 if(Comp("ignition off")==0) {             
    digitalWrite(ledpin = 2, HIGH);  
    digitalWrite(ledpin = 3, HIGH);  
 }
 if(Comp("lock")==0) {             ;
   digitalWrite(ledpin = 5, LOW);
   delay(500);
   digitalWrite(ledpin = 5, HIGH);
 }
 if(Comp("unlock")==0) {
   digitalWrite(ledpin = 5, LOW);
   delay(500);
   digitalWrite(ledpin = 5, HIGH);  
 }
 if(Comp("reset")==0) {              
 
   digitalWrite(ledpin = 2, HIGH);  
   digitalWrite(ledpin = 3, HIGH);  
   digitalWrite(ledpin = 4, HIGH);  
   digitalWrite(ledpin = 5, HIGH);  
 }
 if(Comp("passenger window front up")==0) {              
 
   digitalWrite(ledpin = 7, LOW);
   delay(15000); 
   digitalWrite(ledpin = 7, HIGH);
 }
 if(Comp("passenger window front down")==0) {              
 
   digitalWrite(ledpin = 8, LOW);
   delay(15000); 
   digitalWrite(ledpin = 8, HIGH);
 }
 if(Comp("drivers window front up")==0) {              
 
   digitalWrite(ledpin = 9, LOW);
   delay(15000); 
   digitalWrite(ledpin = 9, HIGH);
 }
 if(Comp("drivers window front down")==0) {              
 
   digitalWrite(ledpin = 10, LOW);
   delay(15000); 
   digitalWrite(ledpin = 10, HIGH);   
 } 
 if(Comp("warm up")==0) {
  digitalWrite(ledpin = 2, HIGH);
  digitalWrite(ledpin = 3, HIGH);
  delay(1000);
   digitalWrite(ledpin = 2, LOW);    
   digitalWrite(ledpin = 3, LOW);    
   delay(2000);
   digitalWrite(ledpin = 4, LOW);  
   delay(1000);                     
   digitalWrite(ledpin = 4, HIGH);
   delay(900000);
   digitalWrite(ledpin = 2, HIGH);
   digitalWrite(ledpin = 3, HIGH);
 }
 if(Comp("cool down")==0) {
   digitalWrite(ledpin = 8, LOW);
   delay(15000); 
   digitalWrite(ledpin = 8, HIGH);
   digitalWrite(ledpin = 10, LOW);
   delay(15000); 
   digitalWrite(ledpin = 10, HIGH);   
   delay(900000);
   digitalWrite(ledpin = 7, LOW);
   delay(15000); 
   digitalWrite(ledpin = 7, HIGH);
   digitalWrite(ledpin = 9, LOW);
   delay(15000); 
   digitalWrite(ledpin = 9, HIGH);
 }
 int reading = digitalRead(button);

//first pressed
if (reading == HIGH && lastReading == LOW) {
  onTime = millis();
}

//held
if (reading == HIGH && lastReading == HIGH) {
  if ((millis() - onTime) > holdTime) {
    invertLED();  
    hold = 1;
  }
}

//released
if (reading == LOW && lastReading == HIGH) {
  if (((millis() - onTime) > bounceTime) && hold != 1) {
    onRelease();
  }
  if (hold == 1) {
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  delay(1000);
   digitalWrite(2, LOW);    
   digitalWrite(3, LOW);    
   delay(2000);
   digitalWrite(4, LOW);  
   delay(1000);                     
   digitalWrite(4, HIGH);
   Serial.print("HOLD");
   digitalWrite(13, HIGH);   
    hold = 0;
  }   
}
lastReading = reading;

if (single == 1 && (millis() - lastSwitchTime) > doubleTime) {
   digitalWrite(2, HIGH);  
   digitalWrite(3, HIGH);
   Serial.print("single");
   digitalWrite(13,LOW);
   delay(200);
   digitalWrite(13,HIGH);
   delay(200);
   digitalWrite(13,LOW);
   delay(200);
   digitalWrite(13,HIGH);
   delay(200);
   digitalWrite(13,LOW);
   delay(200);
   digitalWrite(13,HIGH);
   delay(200);
   digitalWrite(13,LOW);
   delay(200);
   digitalWrite(13,HIGH);
   delay(200);
   digitalWrite(13,LOW);
  single = 0;
}

}


void onRelease() {

if ((millis() - lastSwitchTime) >= doubleTime) {
  single = 1;
  lastSwitchTime = millis();
  return;
}  

if ((millis() - lastSwitchTime) < doubleTime) {
  toggleLED();
   digitalWrite(2, LOW);    
   digitalWrite(3, LOW); 
   digitalWrite(13, HIGH);
  single = 0;
  lastSwitchTime = millis();
}  
}

void toggleLED() {
if (LEDstate == 0) {
  LEDstate = 1;
} else {
  LEDstate = 0;
}
digitalWrite(led, LEDstate);  
} 

void invertLED() {
if (LEDstate == 0) {
digitalWrite(led, 1);
} else {
digitalWrite(led, 0);
}
}

P.S sorry about the rant ive been working for 2 days solid on this and i just got to me

  digitalWrite(ledpin = 2, HIGH);
  digitalWrite(ledpin = 3, HIGH);

You didn't bother to fix this crap.

You are still combining the functionality for reading serial data and the functionality for using that data in one function. That is still wrong.

You are still not properly making packets of the data being sent/received. You are assuming that all serial data will always be sent and received properly. Sooner or later, that is going to bite you in the ass.

What is going to happen if, instead of "start engine" arriving, the stream contains "strt engine"? NOTHING after that will ever trigger proper behavior, because the array is only cleared when the data in the array is recognized as a valid directive.