For use in my acoustic touchscreen project, found here: http://hackaday.io/project/1990-Low-Cost-Touchscreen-Anywhere
Revision 0:d678323f9a72, committed 2014-07-26
- Comitter:
- ThatcherC
- Date:
- Sat Jul 26 16:58:52 2014 +0000
- Child:
- 1:62933cace87a
- Commit message:
- First commit! This code works properly when set up. Monitor the serial port at 9600 baud and you should see the delay between vibrations in seconds sent as an array.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Jul 26 16:58:52 2014 +0000 @@ -0,0 +1,82 @@ +#include "mbed.h" + +DigitalOut myled(dp1); +DigitalOut led2(dp4); +InterruptIn int1(dp14); +InterruptIn int2(dp13); +Timer t; +Timeout reset; +bool first = true; +bool timeAvailable = false; + +void reset1(); +void reset2(); + +float timeArray[3]; //important. this stores the delays between vibration detections + //right now only indices 0 and 1 are used +void flip1(){ + if(first){ + t.start(); + int1.fall(NULL); + first = false; + reset.attach(&reset1,0.01); + }else{ + t.stop(); + timeArray[0]=t.read(); + reset.detach(); + timeAvailable=true; + first = true; + } + myled = 1; +} + +void flip2(){ + if(first){ + t.start(); + int2.fall(NULL); + first = false; + reset.attach(&reset2,0.01); + }else{ + t.stop(); + timeArray[1]=t.read(); + reset.detach(); + timeAvailable=true; + first = true; + } + led2 = 1; +} + +void reset1(){ + t.stop(); + t.reset(); + first = true; + int1.fall(&flip1); +} + +void reset2(){ + t.stop(); + t.reset(); + first = true; + int2.fall(&flip2); +} + +int main() { + int1.fall(&flip1); + int2.fall(&flip2); + timeArray[0] = 0; + timeArray[1] = 0; + timeArray[2] = 0; //for now this isn't used (only two sensors) + while(1){ + if(timeAvailable){ + printf("[%f, %f]\n",timeArray[0],timeArray[1]); + t.reset(); + timeArray[0] = 0; + timeArray[1] = 0; + timeArray[2] = 0; //for now this isn't used (only two sensors) + timeAvailable=false; + wait(.1); + int1.fall(&flip1); + int2.fall(&flip2); + } + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Jul 26 16:58:52 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877 \ No newline at end of file