Hi peeps, just starting playing with my Arduino and having lots of fun. .lol
I am after reading my speedo pulse on my car and am hoping someone could confirm if I'm doing it right.
I will be getting the pulse by using this direct to pin2

The code I have done so far is...
int inPin = 2; // choose the input pin (for pulse count)
int val = 0; // variable for reading the pulse count
int pulseval = 0; // variable for counting pulse
long currentmils = 0; // variable to hold current mills value
int currentspeed = 0; // holds current speed value (needs to be calibrated)
int ledPin = 13; // LED connected to digital pin 13
int ledval = 0;
void setup() {
pinMode(inPin, INPUT); // declare pushbutton as input
currentmils = millis(); // set current millis
Serial.begin(9600); // using serial output so I can monitor whats going on.
pinMode(ledPin, OUTPUT); // sets the digital pin as output
}
void loop(){
if ( val == digitalRead(inPin) ) {
} else {
val = digitalRead(inPin);
pulseval = pulseval + 1;
}
if ((currentmils + 100) < millis()) { // runs every second, will shortern time once calibrated
currentmils = millis();
currentspeed = pulseval / 2; // current speed needs calibrating via GPS, but its a start
Serial.print(currentspeed);
if (ledval == 0 ) {
digitalWrite(ledPin, HIGH);
ledval = 1;
} else {
digitalWrite(ledPin, LOW);
ledval = 0;
}
pulseval = 0;
}
}
I was going to use pulsein but this pauses the code and I need to add few other sensors as well.
For some reason <> doesnt seem to be accepted on == which is why I'm using
if ( val == digitalRead(inPin) ) {
} else {
any advice would help
cheers
Steve