![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
VMA306 Library HelloWorld program
Diff: main.cpp
- Revision:
- 0:9afd9068bcc9
- Child:
- 1:dde51c1d6477
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu May 31 17:35:40 2018 +0000 @@ -0,0 +1,118 @@ +#include "mbed.h" + +Serial pc (PA_2, PA_3, 921600); + +Ticker _tick; +Timer _tim; + +DigitalOut _trig1 (PB_15); +DigitalOut _trig2 (PB_14); +DigitalOut _trig3 (PB_13); + +InterruptIn _echo1 (PA_6); +InterruptIn _echo2 (PC_7); +InterruptIn _echo3 (PB_2); + +DigitalOut led1 (PA_5); +DigitalOut led2 (PD_2); +DigitalOut disquette (PA_12); + + +int start1, start2, start3, FlagMes = 0;; +double dist1, dist2, dist3; + +void monte1 (void) +{ + start1 = _tim.read_us(); + //pc.printf("\n\rE1_ON"); +} + +void monte2 (void) +{ + start2 = _tim.read_us(); + //pc.printf("\n\rE2_ON"); +} + +void monte3 (void) +{ + start3 = _tim.read_us(); + //pc.printf("\n\rE3_ON"); +} + +void tombe1 (void) +{ + dist1 = (double)(_tim.read_us() - start1)/58.0; + if (dist1 > 500) dist1 = 500; + //pc.printf("\n\rE1_OFF"); +} + +void tombe2 (void) +{ + dist2 = (double)(_tim.read_us() - start2)/58.0; + if (dist2 > 500) dist1 = 500; + //pc.printf("\n\rE2_OFF"); +} + +void tombe3 (void) +{ + dist3 = (double)(_tim.read_us() - start3)/58.0; + if (dist3 > 500) dist1 = 500; + FlagMes = 1; + //pc.printf("\n\rE3_OFF"); +} + +void picko (void) +{ + static int etape = 1; + //pc.printf ("\n\rpick : %d",etape); + switch(etape) { + case 1: + _trig1 = 1; + wait_us(20); + _trig1 = 0; + etape = 2; + break; + + case 2: + _trig2 = 1; + wait_us(20); + _trig2 = 0; + etape = 3; + break; + + case 3: + _trig3 = 1; + wait_us(20); + _trig3 = 0; + etape = 1; + break; + } +} + +int main() +{ + _tim.start(); + + _echo1.rise (&monte1); + _echo2.rise (&monte2); + _echo3.rise (&monte3); + + _echo1.fall (&tombe1); + _echo2.fall (&tombe2); + _echo3.fall (&tombe3); + + _tick.attach (&picko, 0.05); + + led1 = 1; + led2 = 0; + disquette = 0; + + while(1) { + if (FlagMes) { + FlagMes = 0; + pc.printf("\rG = %5.2lf - B = %5.2lf - D = %5.2lf", dist1, dist2, dist3); + led1 = !led1; + led2 = !led2; + } + } +}