diff options
author | Stanley Huang <stanleyhuangyc@gmail.com> | 2013-03-25 00:57:28 +0800 |
---|---|---|
committer | Stanley Huang <stanleyhuangyc@gmail.com> | 2013-03-25 00:57:28 +0800 |
commit | 8e57c683d3d16f1dee320f10c411602ea38ba651 (patch) | |
tree | 75df3040d13c3f1850d93e29eb93a3836cae133c /samples/rpm_led | |
download | 2021-arduino-obd-8e57c683d3d16f1dee320f10c411602ea38ba651.tar.gz 2021-arduino-obd-8e57c683d3d16f1dee320f10c411602ea38ba651.tar.bz2 2021-arduino-obd-8e57c683d3d16f1dee320f10c411602ea38ba651.zip |
initial commit
Diffstat (limited to 'samples/rpm_led')
-rw-r--r-- | samples/rpm_led/rpm_led.ino | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/samples/rpm_led/rpm_led.ino b/samples/rpm_led/rpm_led.ino new file mode 100644 index 0000000..415f119 --- /dev/null +++ b/samples/rpm_led/rpm_led.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 <Arduino.h> +#include <OBD.h> + +COBD obd; + +void setup() +{ + // we'll use the debug LED as output + pinMode(13, OUTPUT); + // start serial communication at the adapter defined baudrate + OBDUART.begin(OBD_SERIAL_BAUDRATE); + // initiate OBD-II connection until success + while (!obd.Init()); +} + +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); + } +} |