summaryrefslogtreecommitdiff
path: root/libraries/OBD/examples/rpm_led/rpm_led.ino
blob: c641736b742b1b59e48f7620d5b88b4ccfb708e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*************************************************************************
* Sample sketch based on OBD-II library for Arduino
* Distributed under GPL v2.0
* Copyright (c) 2012-2013 Stanley Huang <stanleyhuangyc@gmail.com>
* All rights reserved.
*************************************************************************/

#include <Arduino.h>
#include "OBD.h"

COBD obd;

void setup()
{
  // we'll use the debug LED as output
  pinMode(13, OUTPUT);  
  // start serial communication at the adapter defined baudrate
  OBDUART.begin(OBD_SERIAL_BAUDRATE);
  // initiate OBD-II connection until success
  while (!obd.Init());  
}

void loop()
{
  int value;
  if (obd.ReadSensor(PID_RPM, value)) {
    // RPM is read and stored in 'value'
    // light on LED when RPM exceeds 5000
    digitalWrite(13, value > 5000 ? HIGH : LOW);
  }
}