Created libraries2
Dependencies: mbed ultrasonic
Diff: main.cpp
- Revision:
- 6:0d4008544238
- Parent:
- 5:b2df25183cb1
- Child:
- 7:c763b5d61dee
- Child:
- 8:454f1f82aca4
--- a/main.cpp Thu Apr 16 10:50:23 2015 +0000 +++ b/main.cpp Thu Apr 16 13:55:42 2015 +0000 @@ -5,38 +5,44 @@ DigitalOut TX2(D8); // Use pin D8 DigitalOut HVoff(D6); // Use pin D6 InterruptIn signal(D7); // Use pin D7 -//DigitalOut tresh(D7); Timeout to1; Timer t1; Serial pc(SERIAL_TX, SERIAL_RX); +float previous = 1; + void TX1_send(){ + + previous = 1; HVoff = 0; - //tresh = 1; TX1.period(0.0000252); // Set the period of TX1 to 25.2us (39,682kHz) TX1.pulsewidth(0.0000116); // Set the pulsewidth of TX1 to 11.6us (ON) wait(0.0002016); // Waits 201.6us TX1 = 0; - //tresh =0; t1.reset(); - HVoff = 1; - //pc.printf("It writes TX1\r\n"); - to1.attach(TX1_send,0.1); // Sends for 1000us - //wait_ms(86); // Waits 86ms. Total 100ms + to1.attach(TX1_send,0.1); // Sends for 1000us } void signal_reciev(){ + float _time = t1.read(); + if (_time<0.006 && _time>0.0007){ - float time = t1.read(); - float cm = 0; + if (t1.read()>previous){ + pc.printf("check"); + } - if (time<0.006 && time>0.0007){ + else{ + + previous = _time; + + float cm = 0; - cm = 34613*time/2; // Calculate distance - pc.printf("%f\r\n", cm); // Prints distance + cm = 34613*_time/2; // Calculate distance + pc.printf("%f\r\n", cm); // Prints distance + } } }