diff options
author | Stanley Huang <stanleyhuangyc@gmail.com> | 2013-11-29 23:13:36 +1100 |
---|---|---|
committer | Stanley Huang <stanleyhuangyc@gmail.com> | 2013-11-29 23:13:36 +1100 |
commit | 5c4300402d931b2cb53db7214877d9b7e69a8416 (patch) | |
tree | f36dcf46b5d0459073a656368899eac0f76b247d /libraries/OBD/examples/rpm_led_i2c | |
parent | 94ddea4cfac60df45f48db3b25b0d9c62c066d94 (diff) | |
download | 2021-arduino-obd-5c4300402d931b2cb53db7214877d9b7e69a8416.tar.gz 2021-arduino-obd-5c4300402d931b2cb53db7214877d9b7e69a8416.tar.bz2 2021-arduino-obd-5c4300402d931b2cb53db7214877d9b7e69a8416.zip |
update OBD-II library
Diffstat (limited to 'libraries/OBD/examples/rpm_led_i2c')
-rw-r--r-- | libraries/OBD/examples/rpm_led_i2c/rpm_led_i2c.ino | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/libraries/OBD/examples/rpm_led_i2c/rpm_led_i2c.ino b/libraries/OBD/examples/rpm_led_i2c/rpm_led_i2c.ino new file mode 100644 index 0000000..c80eba9 --- /dev/null +++ b/libraries/OBD/examples/rpm_led_i2c/rpm_led_i2c.ino @@ -0,0 +1,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 <Wire.h> +#include <OBD.h> + +COBDI2C 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); + } +} |