
For use in my acoustic touchscreen project, found here: http://hackaday.io/project/1990-Low-Cost-Touchscreen-Anywhere
main.cpp
- Committer:
- ThatcherC
- Date:
- 2014-08-09
- Revision:
- 2:2ccbee38f4a8
- Parent:
- 1:62933cace87a
- Child:
- 3:5d221e8f4012
File content as of revision 2:2ccbee38f4a8:
#include "mbed.h" Serial pc(dp16,dp15); 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() { pc.baud(115200); pc.printf("Ready\n"); 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){ int tA0 = int(timeArray[0]*1000000); int tA1 = int(timeArray[1]*1000000); pc.printf("[%i, %i]\n",tA0,tA1); 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); } } }