done

Dependents:   AwesomeAlarm_BLE

Committer:
Nestordp
Date:
Thu Feb 05 23:37:56 2015 +0000
Revision:
2:9daf23ed9d84
Parent:
1:56b2ae08c35e
Carrinho Labirinto

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Nestordp 0:d1d7bb1c1f6c 1 #ifndef HCSR04_H
Nestordp 0:d1d7bb1c1f6c 2 #define HCSR04_H
Nestordp 0:d1d7bb1c1f6c 3
Nestordp 0:d1d7bb1c1f6c 4 #include "mbed.h"
Nestordp 0:d1d7bb1c1f6c 5
Nestordp 0:d1d7bb1c1f6c 6
Nestordp 0:d1d7bb1c1f6c 7
Nestordp 0:d1d7bb1c1f6c 8 /** Sonar HC-SR04 example.
Nestordp 0:d1d7bb1c1f6c 9 * @code
Nestordp 0:d1d7bb1c1f6c 10 * #include "mbed.h"
Nestordp 0:d1d7bb1c1f6c 11 * #include "HCSR04.h"
Nestordp 0:d1d7bb1c1f6c 12 *
Nestordp 0:d1d7bb1c1f6c 13 * Serial pc(USBTX,USBRX);
Nestordp 0:d1d7bb1c1f6c 14 *
Nestordp 0:d1d7bb1c1f6c 15 * HCSR04 sonar(PTB0, PTD3);
Nestordp 0:d1d7bb1c1f6c 16 *
Nestordp 0:d1d7bb1c1f6c 17 * int main() {
Nestordp 0:d1d7bb1c1f6c 18 * while(1) {
Nestordp 1:56b2ae08c35e 19 * printf("Distancia detectada pelo sensor Frente %.2f cm \n", sonar.getCm());
Nestordp 0:d1d7bb1c1f6c 20 * wait_ms(1000);
Nestordp 0:d1d7bb1c1f6c 21 * }
Nestordp 0:d1d7bb1c1f6c 22 * }
Nestordp 0:d1d7bb1c1f6c 23 *
Nestordp 0:d1d7bb1c1f6c 24 * @endcode
Nestordp 0:d1d7bb1c1f6c 25 */
Nestordp 0:d1d7bb1c1f6c 26
Nestordp 0:d1d7bb1c1f6c 27 class HCSR04 {
Nestordp 0:d1d7bb1c1f6c 28 public:
Nestordp 0:d1d7bb1c1f6c 29 /** Constructor, create HC_SR04 instance
Nestordp 0:d1d7bb1c1f6c 30 *
Nestordp 0:d1d7bb1c1f6c 31 * @param trigger TRIG pin
Nestordp 0:d1d7bb1c1f6c 32 * @param echo ECHO pin
Nestordp 0:d1d7bb1c1f6c 33 */
Nestordp 0:d1d7bb1c1f6c 34 HCSR04(PinName trigger, PinName echo);
Nestordp 0:d1d7bb1c1f6c 35
Nestordp 0:d1d7bb1c1f6c 36 /** Faz uma leitura do sonar
Nestordp 0:d1d7bb1c1f6c 37 *
Nestordp 0:d1d7bb1c1f6c 38 * @returns Tempo do pulso echo em microsegundos*/
Nestordp 0:d1d7bb1c1f6c 39 float readEcho(void);
Nestordp 0:d1d7bb1c1f6c 40
Nestordp 0:d1d7bb1c1f6c 41 /** Mede a distância em centímetros "cm"
Nestordp 0:d1d7bb1c1f6c 42 *
Nestordp 0:d1d7bb1c1f6c 43 *@returns Distância em cm
Nestordp 0:d1d7bb1c1f6c 44 */
Nestordp 0:d1d7bb1c1f6c 45 float getCm(void);
Nestordp 0:d1d7bb1c1f6c 46
Nestordp 0:d1d7bb1c1f6c 47 /** Mede a distência em polegadas "in"
Nestordp 0:d1d7bb1c1f6c 48 *
Nestordp 0:d1d7bb1c1f6c 49 *@returns Distência em in*/
Nestordp 0:d1d7bb1c1f6c 50 float getIn(void);
Nestordp 0:d1d7bb1c1f6c 51
Nestordp 0:d1d7bb1c1f6c 52 private:
Nestordp 0:d1d7bb1c1f6c 53 float tdist; //Leitura do tempo transcorrido
Nestordp 0:d1d7bb1c1f6c 54 float distcm; //
Nestordp 0:d1d7bb1c1f6c 55 float distin;
Nestordp 0:d1d7bb1c1f6c 56
Nestordp 0:d1d7bb1c1f6c 57 DigitalOut _t; //Configuração do pino de Trigger
Nestordp 0:d1d7bb1c1f6c 58 DigitalIn _e; //Configuração do pino de Echo
Nestordp 0:d1d7bb1c1f6c 59 Timer _tempo;
Nestordp 0:d1d7bb1c1f6c 60
Nestordp 0:d1d7bb1c1f6c 61 };
Nestordp 0:d1d7bb1c1f6c 62
Nestordp 0:d1d7bb1c1f6c 63 #endif