From 243b5fa4ddd06b845a68abccb0a109584cf0fa38 Mon Sep 17 00:00:00 2001
From: Stanley Huang <stanleyhuangyc@live.com>
Date: Sun, 26 Jun 2016 20:53:03 +0800
Subject: Library and examples for OBD-II UART Adapter MK2

---
 .../examples/rpm_led_uart/rpm_led_uart.ino         | 30 ++++++++++++++++++++++
 1 file changed, 30 insertions(+)
 create mode 100644 libraries/OBD2UART/examples/rpm_led_uart/rpm_led_uart.ino

(limited to 'libraries/OBD2UART/examples/rpm_led_uart/rpm_led_uart.ino')

diff --git a/libraries/OBD2UART/examples/rpm_led_uart/rpm_led_uart.ino b/libraries/OBD2UART/examples/rpm_led_uart/rpm_led_uart.ino
new file mode 100644
index 0000000..3e80ae3
--- /dev/null
+++ b/libraries/OBD2UART/examples/rpm_led_uart/rpm_led_uart.ino
@@ -0,0 +1,30 @@
+/*************************************************************************
+* Sample sketch based on OBD-II library for Arduino
+* Distributed under GPL v2.0
+* Visit http://freematics.com for more information
+* (C)2012-2014 Stanley Huang <stanleyhuangyc@gmail.com>
+*************************************************************************/
+
+#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);
+  }
+}
-- 
cgit v1.2.3