![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Program that execute AEB system
Dependencies: AEB Ultrasonic Controller_Master mbed
main.cpp@0:64a08651b7c0, 2016-06-02 (annotated)
- Committer:
- AndreaAndreoli
- Date:
- Thu Jun 02 21:23:36 2016 +0000
- Revision:
- 0:64a08651b7c0
- Child:
- 1:8cb509a319e5
First commit, not working;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AndreaAndreoli | 0:64a08651b7c0 | 1 | /* |
AndreaAndreoli | 0:64a08651b7c0 | 2 | * An example showing how to use the Ultrasonic library |
AndreaAndreoli | 0:64a08651b7c0 | 3 | */ |
AndreaAndreoli | 0:64a08651b7c0 | 4 | #include "mbed.h" |
AndreaAndreoli | 0:64a08651b7c0 | 5 | #include "Ultrasonic.h" |
AndreaAndreoli | 0:64a08651b7c0 | 6 | #include "Controller_Master.h" |
AndreaAndreoli | 0:64a08651b7c0 | 7 | #include "rtwtypes.h" |
AndreaAndreoli | 0:64a08651b7c0 | 8 | |
AndreaAndreoli | 0:64a08651b7c0 | 9 | DigitalOut led_R(LED_RED); |
AndreaAndreoli | 0:64a08651b7c0 | 10 | DigitalOut led_B(LED_BLUE); |
AndreaAndreoli | 0:64a08651b7c0 | 11 | DigitalIn slave(D6); |
AndreaAndreoli | 0:64a08651b7c0 | 12 | Ticker t; |
AndreaAndreoli | 0:64a08651b7c0 | 13 | float V = 50; |
AndreaAndreoli | 0:64a08651b7c0 | 14 | |
AndreaAndreoli | 0:64a08651b7c0 | 15 | Serial pc(USBTX, USBRX); // tx, rx |
AndreaAndreoli | 0:64a08651b7c0 | 16 | |
AndreaAndreoli | 0:64a08651b7c0 | 17 | void step(); |
AndreaAndreoli | 0:64a08651b7c0 | 18 | |
AndreaAndreoli | 0:64a08651b7c0 | 19 | int main() |
AndreaAndreoli | 0:64a08651b7c0 | 20 | { |
AndreaAndreoli | 0:64a08651b7c0 | 21 | |
AndreaAndreoli | 0:64a08651b7c0 | 22 | Ultrasonic_init(); // Just call this funtion to initialize the ultrasonic sensor |
AndreaAndreoli | 0:64a08651b7c0 | 23 | Controller_Master_U.V = V; |
AndreaAndreoli | 0:64a08651b7c0 | 24 | Controller_Master_U.D_M = read_cm(); |
AndreaAndreoli | 0:64a08651b7c0 | 25 | Controller_Master_U.Slave = slave.read(); |
AndreaAndreoli | 0:64a08651b7c0 | 26 | Controller_Master_initialize(); |
AndreaAndreoli | 0:64a08651b7c0 | 27 | t.attach(&step,0.2); |
AndreaAndreoli | 0:64a08651b7c0 | 28 | while (true) { |
AndreaAndreoli | 0:64a08651b7c0 | 29 | wait(0.2); |
AndreaAndreoli | 0:64a08651b7c0 | 30 | } |
AndreaAndreoli | 0:64a08651b7c0 | 31 | } |
AndreaAndreoli | 0:64a08651b7c0 | 32 | |
AndreaAndreoli | 0:64a08651b7c0 | 33 | |
AndreaAndreoli | 0:64a08651b7c0 | 34 | void step() |
AndreaAndreoli | 0:64a08651b7c0 | 35 | { |
AndreaAndreoli | 0:64a08651b7c0 | 36 | Controller_Master_U.D_M = read_cm(); |
AndreaAndreoli | 0:64a08651b7c0 | 37 | Controller_Master_U.Slave = slave.read(); |
AndreaAndreoli | 0:64a08651b7c0 | 38 | pc.printf("Distance: %f \n", Controller_Master_U.D_M); // Call read_cm() to get the distance in cm |
AndreaAndreoli | 0:64a08651b7c0 | 39 | Controller_Master_step(); |
AndreaAndreoli | 0:64a08651b7c0 | 40 | led_B = Controller_Master_Y.LED_BLUE; |
AndreaAndreoli | 0:64a08651b7c0 | 41 | led_R = Controller_Master_Y.LED_RED; |
AndreaAndreoli | 0:64a08651b7c0 | 42 | } |