Automotive Auto Starter

I have had this idea floating around in my head for a while now and have run into a wall. I don't have enough experience writing code and need some guidance. I have a working prototype that works and starts my truck no problem. However it is very basic, it uses one switch to turn the truck on and a separate switch to turn it off. I am trying to do all this with one switch. Hit it once to turn on and once to turn off. I also want to add a clutch switch so when the clutch is not pressed the truck wont start. That way the truck can't be started while in gear. Also if the button is pressed with out the clutch i would like only the radio to turn on. Below is a copy of my current code. Its basic but it works. If anyone could point me in the right direction or show me some code snippets, that would be awesome.

const int TacSig = 1; // select the input pin for the Tachometer Signal
const int thresold = 40; // tach signal thresold
const int start = 12; // starter relay
const int acc = 10; //acc relay
const int run = 9; //run relay

const int buttonoff = 4;//inout pin for off button
const int buttonstart = 5; // input pin for start button

int RPM = 0; // variable to store RPM
int buttonstatestart = 0; //variable to store buttonstate
int buttonstateoff = 0; //variable to store buttonstate

void setup() {
pinMode (start, OUTPUT);
pinMode (acc, OUTPUT);
pinMode (run, OUTPUT);

Serial.begin(9600); // use the serial port to send the values back to the computer
}

void loop() {

{
RPM = analogRead(TacSig); // read the value from the sensor
Serial.println(RPM); // print the value to the serial port
}

{buttonstatestart = digitalRead(buttonstart); }
{buttonstateoff = digitalRead(buttonoff); }

if (buttonstatestart == HIGH)

{
digitalWrite(start, HIGH);
digitalWrite(acc, LOW);
digitalWrite(run, HIGH);
}

if (RPM > thresold)

{
digitalWrite(start, LOW);
digitalWrite(acc, HIGH);
}

if (buttonstateoff == HIGH)

{
digitalWrite(run, LOW);
digitalWrite(start, LOW);
digitalWrite(acc, LOW);
}
}

Hi,
first I suggest to use a debounce function to read the digital signals coming from mechanical buttons (there is an Arduino library to do this Arduino Playground - Bounce). Then you need to save the current ON/OFF state and update it as shown below:

#include <Bounce.h>

// ... your variables ...

#define ENGINE_OFF 0
#define ENGINE_ON  1

int currentState = ENGINE_OFF; 

Bounce btnOnOff = Bounce( 4, 10 ); // input pin for start and off button (pin 4)
Bounce btnClutch = Bounce( 5, 10 ); // input pin for clutch (pin 5)

void setup(){
// ...
}

void loop() {
   
   RPM = analogRead(TacSig); // read the value from the sensor
   Serial.println(RPM); // print the value to the serial port
  
   // read the buttons state
   int clutch = btnClutch.update(); 
   int start = btnOnOff.update();
  
   if( start == HIGH ) // if start button is pressed
   {
      if( currentState == ENGINE_OFF )
      {
          // execute start procedure (read the clutch value if needed using clutch.read() ).
          // update the current state (currentState = ENGINE_ON) only if the engine
          // is started.
      }
      else
      {
          // execute the stop procedure and update the current state (currentState = ENGINE_OFF)
      }
   } 
}
   {
  RPM = analogRead(TacSig); // read the value from the sensor
Serial.println(RPM); // print the value to the serial port
   }
 
    {buttonstatestart = digitalRead(buttonstart); }
    {buttonstateoff = digitalRead(buttonoff); }

What's with all the extra curly braces? This section of code does not need any curly braces.

  if (buttonstatestart == HIGH)
     
      {
      digitalWrite(start, HIGH);
      digitalWrite(acc, LOW);
      digitalWrite(run, HIGH);
      }

Every time through loop that the button state is HIGH, it will execute this code. That is NOT what you want. You only want to execute this code when the state is HIGH now and was not HIGH last time.