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);
}
}