Hi all, excuse the noobish post.
I've been working on a remote vehicle ignition for some time now, and have gotton over many hurdles thanks to members on this forum, and have learnt quite alot to something very new to me.
Currently, i'm at the programming stage.
I have had some coding help from a member here in the past, he wrote quite alot of the current code i am using. (i'm more of a designer rather than a programmer)
Here i have my current code, which is giving me a compile error of
arduino_remote_start_final.cpp: In function 'void HandleStoppedState()':
arduino_remote_start_final:150: error: a function-definition is not allowed here before '{' token
arduino_remote_start_final:160: error: expected `}' at end of input
arduino_remote_start_final:160: error: expected `}' at end of input
arduino_remote_start_final:160: error: expected `}' at end of input
My current code is:
//Remote Vehicle Ignition
//State Machine begin
#include <SoftwareSerial.h>
char inchar;
SoftwareSerial cell(2,3);
// system states
#define STOPPED 0
#define STARTING 1
#define CRANKING 2
#define RUNNING 3
#define FUEL_PUMP_PRIME_TIME 5000
#define RUNNING_TIMEOUT 60000UL
const int ignitionPin = 12;
const int onPin = 11;
const int ledPin = 13;
const int onledPin = 9;
const int alternatorPin = 4;
int state = STOPPED; // master variable for the state machine
unsigned long StartingTime; // fuel pump priming
unsigned long RunningTime; // ten minute timeout
void setup()
{
pinMode(onPin, OUTPUT);
pinMode(onledPin, OUTPUT);
pinMode(ignitionPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(alternatorPin,INPUT);
Stop();
cell.begin(9600);
delay(30000);
cell.println("AT+CMGF=1");
delay(200);
cell.println("AT+CNMI=3,3,0,0");
delay(200);
}
void loop()
{
switch(state)
{
case STOPPED:
HandleStoppedState();
break;
case STARTING:
HandleStartingState();
break;
case CRANKING:
HandleCrankingState();
break;
case RUNNING:
if(millis()-RunningTime > RUNNING_TIMEOUT)
{
Serial.println("Running Timeout");
Stop();
}
break;
default:
Serial.print("Unknown State: ");
Serial.println(state);
Stop();
break;
}
}
void Stop()
{
Serial.println("TimeOut");
digitalWrite(ignitionPin,LOW);
digitalWrite(onPin,LOW);
digitalWrite(onledPin,LOW);
state=STOPPED;
}
void HandleStartingState()
{
if(millis()-StartingTime > FUEL_PUMP_PRIME_TIME)
{
if(digitalRead(alternatorPin)==HIGH)
{
Serial.println("Abort cranking");
Stop();
}
else
{
Serial.println("Starting Vehicle");
digitalWrite(onPin,HIGH);
digitalWrite(ignitionPin,HIGH);
state=CRANKING;
}
}
}
void HandleStoppedState()
{
if(cell.available() >0)
{
inchar=cell.read();
if (inchar=='#')
{
delay(10);
inchar=cell.read();
if (inchar=='s')
{
delay(10);
inchar=cell.read();
if (inchar=='0')
{
digitalWrite(ignitionPin,LOW);
digitalWrite(onPin,LOW);
}
else if (inchar=='1')
{
Serial.println("Priming Fuel Pump");
StartingTime=millis();
digitalWrite(ignitionPin,LOW);
digitalWrite(onPin,HIGH);
state=STARTING;
}
}
void HandleCrankingState()
{
if(digitalRead(alternatorPin)==HIGH)
{
Serial.println("Vehicle Running");
digitalWrite(ignitionPin,LOW);
digitalWrite(onPin,HIGH);
digitalWrite(onledPin,HIGH);
RunningTime=millis();
state=RUNNING;
}
}
I've tried a few work around's but cannot seem to get past this.
If anyone would have some idea's, that would be greatly appreciated.
Using an Arduino UNO, with a sparkfun eval board which uses the SM5100b cell chip
This is the code before i wrote in the cell components, for testing i was using serial input.
//Remote Vehicle Ignition
//State Machine begin
// system states
#define STOPPED 0
#define STARTING 1
#define CRANKING 2
#define RUNNING 3
#define FUEL_PUMP_PRIME_TIME 5000
#define RUNNING_TIMEOUT 60000UL
const int ignitionPin = 12;
const int onPin = 11;
const int ledPin = 13;
const int onledPin = 9;
const int alternatorPin = 4;
int state = STOPPED; // master variable for the state machine
unsigned long StartingTime; // fuel pump priming
unsigned long RunningTime; // ten minute timeout
void setup()
{
pinMode(onPin, OUTPUT);
pinMode(onledPin, OUTPUT);
pinMode(ignitionPin, OUTPUT);
pinMode(ledPin, OUTPUT);
pinMode(alternatorPin,INPUT);
Stop(); //
Serial.begin(9600);
}
void loop()
{
switch(state)
{
case STOPPED:
HandleStoppedState();
break;
case STARTING:
HandleStartingState();
break;
case CRANKING: //
HandleCrankingState();
break;
case RUNNING:
if(millis()-RunningTime > RUNNING_TIMEOUT)
{
Serial.println("Running Timeout");
Stop();
}
break;
default:
Serial.print("Unknown State: ");
Serial.println(state);
Stop(); // Should never get here
break;
}
}
void Stop()
{
Serial.println("TimeOut");
digitalWrite(ignitionPin,LOW);
digitalWrite(onPin,LOW);
digitalWrite(onledPin,LOW);
state=STOPPED;
}
void HandleStartingState()
{
if(millis()-StartingTime > FUEL_PUMP_PRIME_TIME)
{
if(digitalRead(alternatorPin)==HIGH)
{
Serial.println("Abort cranking");
Stop();
}
else
{
Serial.println("Starting Vehicle");
digitalWrite(onPin,HIGH);
digitalWrite(ignitionPin,HIGH);
state=CRANKING;
}
}
}
void HandleStoppedState()
{
if (Serial.available() > 0)
{
Serial.read();
Serial.println("Priming Fuel Pump");
StartingTime=millis();
digitalWrite(ignitionPin,LOW);
digitalWrite(onPin,HIGH);
state=STARTING;
}
}
void HandleCrankingState()
{
if(digitalRead(alternatorPin)==HIGH)
{
Serial.println("Vehicle Running");
digitalWrite(ignitionPin,LOW);
digitalWrite(onPin,HIGH);
digitalWrite(onledPin,HIGH);
RunningTime=millis();
state=RUNNING;
}
}
Basically, i need the HandleStoppedState to be initiated upon recieving '#s1'