Code: Select all
#include <Arduino.h>
#include <Wire.h>
#include <OBD.h>
#define LEDPin 13
COBDI2C obd;
void flashLED (int times) {
int pls=180;
for (int i=0;i<times;i++) {
digitalWrite(LEDPin,HIGH);
delay(pls);
digitalWrite(LEDPin,LOW);
delay(pls);
}
}
void setup()
{
// we'll use the debug LED as output
pinMode(13, OUTPUT);
// start communication with OBD-II UART adapter
flashLED(4);
delay(500);
obd.begin();
flashLED(6);
// initiate OBD-II connection until success
while (!obd.init());
flashLED(8);
}
void loop()
{
int value;
if (obd.read(PID_RPM, value)) {
// RPM is successfully read and its value stored in variable 'value'
// light on LED when RPM exceeds 3000
digitalWrite(13, value > 2000 ? HIGH : LOW);
}
}