You can reduce the number of braces by reversing the logic, to a certain extent, eg. instead of:
void HandleCrankingState()
{
if(digitalRead(alternatorPin)==HIGH)
{
Serial.println("Vehicle Running");
digitalWrite(ignitionPin,LOW);
digitalWrite(onPin,HIGH);
digitalWrite(onledPin,HIGH);
RunningTime=millis();
state=RUNNING;
}
}
You can do this:
void HandleCrankingState()
{
if(digitalRead(alternatorPin)==LOW)
return;
Serial.println("Vehicle Running");
digitalWrite(ignitionPin,LOW);
digitalWrite(onPin,HIGH);
digitalWrite(onledPin,HIGH);
RunningTime=millis();
state=RUNNING;
}
Now you don't have as many nested braces.
A good rule of thumb when coding is to always write the closing brace as you write the opening one. Eg. writing your original code:
void HandleCrankingState()
{
<---- write the closing brace and up-arrow to here to write the function
} // end of HandleCrankingState
The comment says why the brace is there.
Then:
void HandleCrankingState()
{
if(digitalRead(alternatorPin)==HIGH)
{
<---- write the closing brace and up-arrow to inside the "if"
} // if alternatorPin is HIGH
} // end of HandleCrankingState
Get into the habit of doing that and these problems will go away.