diff options
Diffstat (limited to 'libraries/OBD')
-rw-r--r-- | libraries/OBD/OBD.cpp | 4 | ||||
-rw-r--r-- | libraries/OBD/OBD.h | 4 | ||||
-rw-r--r-- | libraries/OBD/examples/rpm_led_i2c/rpm_led_i2c.ino (renamed from libraries/OBD/examples/rpm_led/rpm_led.ino) | 15 | ||||
-rw-r--r-- | libraries/OBD/examples/rpm_led_uart/rpm_led_uart.ino | 30 |
4 files changed, 39 insertions, 14 deletions
diff --git a/libraries/OBD/OBD.cpp b/libraries/OBD/OBD.cpp index 5dcf903..3360d07 100644 --- a/libraries/OBD/OBD.cpp +++ b/libraries/OBD/OBD.cpp @@ -75,7 +75,7 @@ void COBD::sendQuery(unsigned char pid) write(cmd); } -bool COBD::readSensor(byte pid, int& result, bool passive) +bool COBD::read(byte pid, int& result, bool passive) { // send a query command sendQuery(pid); @@ -341,7 +341,7 @@ bool COBDI2C::init() } } -bool COBDI2C::readSensor(byte pid, int& result, bool passive) +bool COBDI2C::read(byte pid, int& result, bool passive) { uint32_t t = millis(); sendQuery(pid); diff --git a/libraries/OBD/OBD.h b/libraries/OBD/OBD.h index f64ea35..93856d6 100644 --- a/libraries/OBD/OBD.h +++ b/libraries/OBD/OBD.h @@ -50,7 +50,7 @@ public: COBD():dataMode(1),errors(0),m_state(OBD_DISCONNECTED) {} virtual void begin(); virtual bool init(bool passive = false); - virtual bool readSensor(byte pid, int& result, bool passive = false); + virtual bool read(byte pid, int& result, bool passive = false); virtual void sleep(int seconds); // Query and GetResponse for advanced usage only virtual void sendQuery(byte pid); @@ -118,7 +118,7 @@ class COBDI2C : public COBD { public: void begin(byte addr = I2C_ADDR); bool init(); - bool readSensor(byte pid, int& result, bool passive = false); + bool read(byte pid, int& result, bool passive = false); void write(char* s); // Bluetooth communication API bool btInit(uint16_t baudrate = 9600); diff --git a/libraries/OBD/examples/rpm_led/rpm_led.ino b/libraries/OBD/examples/rpm_led_i2c/rpm_led_i2c.ino index 630336c..c80eba9 100644 --- a/libraries/OBD/examples/rpm_led/rpm_led.ino +++ b/libraries/OBD/examples/rpm_led_i2c/rpm_led_i2c.ino @@ -5,15 +5,10 @@ * All rights reserved. *************************************************************************/ -#include <Arduino.h> #include <Wire.h> #include <OBD.h> -// OBD-II UART Adapter -COBD obd; - -// OBD-II I2C Adapter -//COBDI2C obd; +COBDI2C obd; void setup() { @@ -28,9 +23,9 @@ void setup() 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); + 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 > 3000 ? HIGH : LOW); } } diff --git a/libraries/OBD/examples/rpm_led_uart/rpm_led_uart.ino b/libraries/OBD/examples/rpm_led_uart/rpm_led_uart.ino new file mode 100644 index 0000000..8a2ae42 --- /dev/null +++ b/libraries/OBD/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 +* Copyright (c) 2012-2013 Stanley Huang <stanleyhuangyc@gmail.com> +* All rights reserved. +*************************************************************************/ + +#include <OBD.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.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 > 3000 ? HIGH : LOW); + } +} |