thread ultrasuoni
Dependencies: HCSR04 mbed-rtos mbed
Revision 0:6010d94e58c0, committed 2017-03-06
- Comitter:
- Wonderjack996
- Date:
- Mon Mar 06 16:15:39 2017 +0000
- Commit message:
- thread e ultrasuoni
;
Changed in this revision
diff -r 000000000000 -r 6010d94e58c0 HCSR04.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HCSR04.lib Mon Mar 06 16:15:39 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/prabhuvd/code/HCSR04/#71da0dbf4400
diff -r 000000000000 -r 6010d94e58c0 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Mar 06 16:15:39 2017 +0000 @@ -0,0 +1,51 @@ +/**************************************************** +* FAST PROTOTYPING WITH NUCLEO * +* Example Code 13: Ultrasound HCSR04 * +* Author: Mauro D'Angelo * +* Organization: Perlatecnica no-profit organization * +*****************************************************/ + +#include "mbed.h" +#include "hcsr04.h" +#include "rtos.h" + +// Instanzio un oggetto di tipo HCSR04 ed assegno i pin di trigger e di echo +HCSR04 sensor(PB_8, PB_9); +HCSR04 sensor1(PA_5, PA_6); + +DigitalOut led(D11); + +// Serial +Serial pc(USBTX, USBRX); + +int distanza; + +void thread(void const *args) { + // Main loop + while(1) { + // Avvia un impulso della durata di 10us sul pin di trigger + sensor.start(); + + // Aspetta prima della prossima lettura + wait_ms(100); + + // Stampa sulla seriale la misura della distanza in cm + distanza = sensor.get_dist_cm(); + pc.printf("%dcm\r\n", distanza); + } +} + +int main() { + // Fisso il baudrate + pc.baud(9600); + + Thread th(thread); // Threads start here + + while(1){ + if(distanza < 20) + led = 1; + else + led = 0; + } +} +
diff -r 000000000000 -r 6010d94e58c0 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Mon Mar 06 16:15:39 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
diff -r 000000000000 -r 6010d94e58c0 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Mar 06 16:15:39 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/ef9c61f8c49f \ No newline at end of file