diff options
Diffstat (limited to 'libraries/OBD/examples/rpm_led_uart')
-rw-r--r-- | libraries/OBD/examples/rpm_led_uart/rpm_led_uart.ino | 30 |
1 files changed, 30 insertions, 0 deletions
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); + } +} |