From c6d9812fd7caaf52d2add06e7cb897fbaf1b05f9 Mon Sep 17 00:00:00 2001 From: Rui Azevedo Date: Thu, 7 Sep 2017 13:47:54 +0000 Subject: [PATCH] added tachometer example --- .gitignore | 6 +++- examples/tachometer/.gitignore | 4 +++ examples/tachometer/tachometer/tachometer.ino | 31 +++++++++++++++++++ library.properties | 4 +-- 4 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 examples/tachometer/.gitignore create mode 100644 examples/tachometer/tachometer/tachometer.ino diff --git a/.gitignore b/.gitignore index 480ac6d..6aaa6ab 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,8 @@ .clang_complete .gcc-flags.json .piolibdeps -*.gch \ No newline at end of file +*.gch +lib +.travis.yml +!/.travis.yml +platformio.ini diff --git a/examples/tachometer/.gitignore b/examples/tachometer/.gitignore new file mode 100644 index 0000000..5dac9f5 --- /dev/null +++ b/examples/tachometer/.gitignore @@ -0,0 +1,4 @@ +.pioenvs +.piolibdeps +.clang_complete +.gcc-flags.json diff --git a/examples/tachometer/tachometer/tachometer.ino b/examples/tachometer/tachometer/tachometer.ino new file mode 100644 index 0000000..c08665f --- /dev/null +++ b/examples/tachometer/tachometer/tachometer.ino @@ -0,0 +1,31 @@ +//simple tachometer sending data to serial port +//it only prints rpm's of the last measure + +#include + +#define SensorPin 2 + +volatile unsigned long t=0; +volatile unsigned long ot=0; +unsigned int rpm=0; + +void tick() { + ot=t; + t=millis(); +} + +void setup() { + Serial.begin(9600); + while(!Serial); + pinMode(SensorPin,INPUT_PULLUP); + PCattachInterrupt(tick,RISING); +} + +void loop() { + if((millis()-t)>300) rpm=0; + else if (t!=ot) rpm=60000.0/(float)(t-ot); + Serial.print(rpm); + Serial.print(" "); + Serial.println(t-ot); + delay(100); +} diff --git a/library.properties b/library.properties index c4fc092..e6026e7 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ name=PCINT r-site.net -version=4.0.3 +version=4.0.4 author=Rui Azevedo, ruihfazevedo@gmail.com maintainer=neu-rah, ruihfazevedo@gmail.com sentence=Arduino Pin change monitor paragraph=Attach user function and data to pin change events. -category=Uncategorized +category=Signal Input dot_a_linkage=true url=https://github.com/neu-rah/PCINT architectures=*