summaryrefslogtreecommitdiff
path: root/libraries/OBD2UART/examples/rpm_led_uart/rpm_led_uart.ino
blob: 5b7a13e7aeded66ea5458c79cf696c567df99bba (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
/*************************************************************************
* Testing sketch for Freematics OBD-II UART Adapter
* Reads engine RPM data from OBD and triggers Arduino onboard LED
* Distributed under BSD
* Visit https://freematics.com/products for more product information
* Written by Stanley Huang <stanley@freematics.com.au>
*************************************************************************/

#include <OBD2UART.h>

COBD obd;

void setup()
{
  // we'll use the debug LED as output
  pinMode(13, OUTPUT);  
  // start communication with OBD-II UART adapter
  obd.begin();
  // initiate OBD-II connection until success
  while (!obd.init());  
}

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