Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of STMNucleoF401RE_ExampleCode_13_Ultasound by
main.cpp@0:a4f31fdfb261, 2015-11-02 (annotated)
- Committer:
- perlatecnica
- Date:
- Mon Nov 02 14:24:27 2015 +0000
- Revision:
- 0:a4f31fdfb261
v1.0
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| perlatecnica | 0:a4f31fdfb261 | 1 | /**************************************************** |
| perlatecnica | 0:a4f31fdfb261 | 2 | * FAST PROTOTYPING WITH NUCLEO * |
| perlatecnica | 0:a4f31fdfb261 | 3 | * Example Code 13: Ultrasound HCSR04 * |
| perlatecnica | 0:a4f31fdfb261 | 4 | * Author: Mauro D'Angelo * |
| perlatecnica | 0:a4f31fdfb261 | 5 | * Organization: Perlatecnica no-profit organization * |
| perlatecnica | 0:a4f31fdfb261 | 6 | *****************************************************/ |
| perlatecnica | 0:a4f31fdfb261 | 7 | |
| perlatecnica | 0:a4f31fdfb261 | 8 | #include "mbed.h" |
| perlatecnica | 0:a4f31fdfb261 | 9 | #include "hcsr04.h" |
| perlatecnica | 0:a4f31fdfb261 | 10 | |
| perlatecnica | 0:a4f31fdfb261 | 11 | // Instanzio un oggetto di tipo HCSR04 ed assegno i pin di trigger e di echo |
| perlatecnica | 0:a4f31fdfb261 | 12 | HCSR04 sensor(PB_8, PB_9); |
| perlatecnica | 0:a4f31fdfb261 | 13 | |
| perlatecnica | 0:a4f31fdfb261 | 14 | // Serial |
| perlatecnica | 0:a4f31fdfb261 | 15 | Serial pc(USBTX, USBRX); |
| perlatecnica | 0:a4f31fdfb261 | 16 | |
| perlatecnica | 0:a4f31fdfb261 | 17 | int main() { |
| perlatecnica | 0:a4f31fdfb261 | 18 | // Fisso il baudrate |
| perlatecnica | 0:a4f31fdfb261 | 19 | pc.baud(9600); |
| perlatecnica | 0:a4f31fdfb261 | 20 | |
| perlatecnica | 0:a4f31fdfb261 | 21 | // Main loop |
| perlatecnica | 0:a4f31fdfb261 | 22 | while(1) { |
| perlatecnica | 0:a4f31fdfb261 | 23 | // Avvia un impulso della durata di 10us sul pin di trigger |
| perlatecnica | 0:a4f31fdfb261 | 24 | sensor.start(); |
| perlatecnica | 0:a4f31fdfb261 | 25 | |
| perlatecnica | 0:a4f31fdfb261 | 26 | // Aspetta prima della prossima lettura |
| perlatecnica | 0:a4f31fdfb261 | 27 | wait_ms(100); |
| perlatecnica | 0:a4f31fdfb261 | 28 | |
| perlatecnica | 0:a4f31fdfb261 | 29 | // Stampa sulla seriale la misura della distanza in cm |
| perlatecnica | 0:a4f31fdfb261 | 30 | pc.printf("%dcm\r\n", sensor.get_dist_cm()); |
| perlatecnica | 0:a4f31fdfb261 | 31 | } |
| perlatecnica | 0:a4f31fdfb261 | 32 | } |
