ultrasonic sensors for roboticized zuca project
Dependencies: HC_SR04_Ultrasonic_Library mbed
Fork of Nucleo_UltrasonicHelloWorld by
main.cpp@3:d0e45e12a03f, 2017-07-21 (annotated)
- Committer:
- Abraxas3d
- Date:
- Fri Jul 21 17:57:01 2017 +0000
- Revision:
- 3:d0e45e12a03f
- Parent:
- 2:1673deaeefad
Put in comment and question about supporting multiple ultrasonic sensors on the mBed.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ejteb | 0:1704ea055c4f | 1 | #include "mbed.h" |
ejteb | 0:1704ea055c4f | 2 | #include "ultrasonic.h" |
ejteb | 0:1704ea055c4f | 3 | |
Abraxas3d | 2:1673deaeefad | 4 | Serial pc(USBTX, USBRX); // tx, rx |
Abraxas3d | 2:1673deaeefad | 5 | |
ejteb | 0:1704ea055c4f | 6 | void dist(int distance) |
ejteb | 0:1704ea055c4f | 7 | { |
ejteb | 1:4a5586eb1765 | 8 | //put code here to happen when the distance is changed |
Abraxas3d | 2:1673deaeefad | 9 | pc.printf("Distance changed to %dmm\r\n", distance); |
Abraxas3d | 2:1673deaeefad | 10 | //pc.printf("Distance changed!\n"); |
Abraxas3d | 2:1673deaeefad | 11 | //printf("Distance changed!\r\n"); |
ejteb | 0:1704ea055c4f | 12 | } |
ejteb | 0:1704ea055c4f | 13 | |
Abraxas3d | 2:1673deaeefad | 14 | //ultrasonic mu(D8, D9, .1, 1, &dist); //Set the trigger pin to D8 and the echo pin to D9 |
Abraxas3d | 2:1673deaeefad | 15 | //have updates every .1 seconds and a timeout after 1 |
Abraxas3d | 2:1673deaeefad | 16 | //second, and call dist when the distance changes |
Abraxas3d | 2:1673deaeefad | 17 | |
Abraxas3d | 2:1673deaeefad | 18 | ultrasonic mu(p30, p29, .1, 1, &dist); //Set the trigger pin to D30 and the echo pin to D29 |
ejteb | 1:4a5586eb1765 | 19 | //have updates every .1 seconds and a timeout after 1 |
ejteb | 1:4a5586eb1765 | 20 | //second, and call dist when the distance changes |
Abraxas3d | 3:d0e45e12a03f | 21 | |
Abraxas3d | 3:d0e45e12a03f | 22 | //Other sensors can be declared here. |
Abraxas3d | 3:d0e45e12a03f | 23 | //ultrasonic nu(pwhatever, pwhatever, .1, 1, &distNu); |
Abraxas3d | 3:d0e45e12a03f | 24 | //Then we can have multiple independent sensors that each are interrupt driven? |
Abraxas3d | 3:d0e45e12a03f | 25 | //I'm worried that I don't understand enough about interrupts and counting that this will work. |
ejteb | 0:1704ea055c4f | 26 | |
ejteb | 0:1704ea055c4f | 27 | int main() |
ejteb | 0:1704ea055c4f | 28 | { |
Abraxas3d | 2:1673deaeefad | 29 | mu.startUpdates();//start measuring the distance |
ejteb | 0:1704ea055c4f | 30 | while(1) |
ejteb | 0:1704ea055c4f | 31 | { |
ejteb | 1:4a5586eb1765 | 32 | //Do something else here |
ejteb | 1:4a5586eb1765 | 33 | mu.checkDistance(); //call checkDistance() as much as possible, as this is where |
ejteb | 1:4a5586eb1765 | 34 | //the class checks if dist needs to be called. |
ejteb | 0:1704ea055c4f | 35 | } |
ejteb | 0:1704ea055c4f | 36 | } |