![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
VMA306 Library HelloWorld program
Diff: main.cpp
- Revision:
- 1:dde51c1d6477
- Parent:
- 0:9afd9068bcc9
--- a/main.cpp Thu May 31 17:35:40 2018 +0000 +++ b/main.cpp Fri Jun 01 07:29:32 2018 +0000 @@ -1,118 +1,29 @@ #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); - +#include "VMA306.h" -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"); -} +Serial pc (PA_2, PA_3, 921600); // Create a serial link to PC for communication -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"); -} +VMA306 UltraSon (PB_15, PA_6, PB_14, PC_7, PB_13, PB_2); // Create 3 ultrasonic sensors (1 and 2 sensor support will be added) -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; - } -} +DigitalOut led1 (PA_5); // Added Led1 for test purpose +DigitalOut led2 (PD_2); // Added Led2 for test purpose +DigitalOut disquette (PA_12); // Added baloon destructor command (without it, you might see baloon destructor motor be set to full speed) 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; + led1 = 1; // Led1 switch ON + led2 = 0; // Led2 switch OFF + disquette = 0; // Baloon destructor switch OFF while(1) { - if (FlagMes) { - FlagMes = 0; - pc.printf("\rG = %5.2lf - B = %5.2lf - D = %5.2lf", dist1, dist2, dist3); - led1 = !led1; - led2 = !led2; - } + if (UltraSon.isUSGReady()) pc.printf ("\rusG = %5.2lf -", UltraSon.readUSG()); // If left ultra sonic seonsor has a mesurment print it + else pc.printf ("\r -"); // Else delete previous display of USG value + if (UltraSon.isUSBReady()) pc.printf ("\r\t\t usB = %5.2lf -", UltraSon.readUSB()); // If back ultra sonic seonsor has a mesurment print it + else pc.printf ("\r\t\t -"); // Else delete previous display of USB value + if (UltraSon.isUSDReady()) pc.printf ("\r\t\t\t\t usD = %5.2lf", UltraSon.readUSD()); // If right ultra sonic seonsor has a mesurment print it + else pc.printf ("\r\t\t\t\t "); // Else delete previous display of USB value + + led1 = !led1; // Switch Led1 + led2 = !led2; // Switch Led2 } }