dillerdasker
Dependents: RoboticHackathon RoboticHackathon2 RoboticHackathonFINAL
HCSR04.h
- Committer:
- iLyngklip
- Date:
- 2014-04-05
- Revision:
- 0:506625fdcd0e
- Child:
- 1:d9083ad270f5
File content as of revision 0:506625fdcd0e:
//Library for controlling ultrasonic module HCSR04 //Ported by hiawoood from arduino library orgininally created by ITead studio. //Instantiate object by supplying the proper pin numbers of "trigger" and "echo" //e.g. /* #include "mbed.h" #include "HCSR04.h" Serial pc(USBTX, USBRX); int main() { HCSR04 sensor(PTE1, PTB3); while(1){ long distance = sensor.distance(CM); pc.printf("Distance: %ld \r\n", distance); wait(0.1); } } */ #ifndef HCSR04_H #define HCSR04_H #include "mbed.h" #define CM 1 #define INC 0 class HCSR04 { public: HCSR04(PinName t, PinName e); long echo_duration(); long distance(int sys); HCSR05(); long Echo_duration(); long Distance(int sys); private: DigitalOut trig; DigitalIn echo; Timer timer; long duration,distacne_cm,distance_inc; }; #endif