ECE 4180 Project for Spring 2020

Dependencies:   mbed mbed-rtos SDFileSystem PinDetect ESP8266NodeMCUInterface

Committer:
kimberlylie99
Date:
Fri May 01 18:43:13 2020 +0000
Revision:
1:5ae291085f75
Parent:
0:b97c07227845
Edit Main.cpp;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kimberlylie99 0:b97c07227845 1 #ifndef MBED_ULTRASONIC_H
kimberlylie99 0:b97c07227845 2 #define MBED_ULTRASONIC_H
kimberlylie99 0:b97c07227845 3
kimberlylie99 0:b97c07227845 4 #include "mbed.h"
kimberlylie99 0:b97c07227845 5
kimberlylie99 0:b97c07227845 6 class ultrasonic
kimberlylie99 0:b97c07227845 7 {
kimberlylie99 0:b97c07227845 8 public:
kimberlylie99 0:b97c07227845 9 /**iniates the class with the specified trigger pin, echo pin, update speed and timeout**/
kimberlylie99 0:b97c07227845 10 ultrasonic(PinName trigPin, PinName echoPin, float updateSpeed, float timeout);
kimberlylie99 0:b97c07227845 11 /**iniates the class with the specified trigger pin, echo pin, update speed, timeout and method to call when the distance changes**/
kimberlylie99 0:b97c07227845 12 ultrasonic(PinName trigPin, PinName echoPin, float updateSpeed, float timeout, void onUpdate(int));
kimberlylie99 0:b97c07227845 13 /** returns the last measured distance**/
kimberlylie99 0:b97c07227845 14 int getCurrentDistance(void);
kimberlylie99 0:b97c07227845 15 /**pauses measuring the distance**/
kimberlylie99 0:b97c07227845 16 void pauseUpdates(void);
kimberlylie99 0:b97c07227845 17 /**starts mesuring the distance**/
kimberlylie99 0:b97c07227845 18 void startUpdates(void);
kimberlylie99 0:b97c07227845 19 /**attachs the method to be called when the distances changes**/
kimberlylie99 0:b97c07227845 20 void attachOnUpdate(void method(int));
kimberlylie99 0:b97c07227845 21 /**changes the speed at which updates are made**/
kimberlylie99 0:b97c07227845 22 void changeUpdateSpeed(float updateSpeed);
kimberlylie99 0:b97c07227845 23 /**gets whether the distance has been changed since the last call of isUpdated() or checkDistance()**/
kimberlylie99 0:b97c07227845 24 int isUpdated(void);
kimberlylie99 0:b97c07227845 25 /**gets the speed at which updates are made**/
kimberlylie99 0:b97c07227845 26 float getUpdateSpeed(void);
kimberlylie99 0:b97c07227845 27 /**call this as often as possible in your code, eg. at the end of a while(1) loop,
kimberlylie99 0:b97c07227845 28 and it will check whether the method you have attached needs to be called**/
kimberlylie99 0:b97c07227845 29 void checkDistance(void);
kimberlylie99 0:b97c07227845 30 private:
kimberlylie99 0:b97c07227845 31 DigitalOut _trig;
kimberlylie99 0:b97c07227845 32 InterruptIn _echo;
kimberlylie99 0:b97c07227845 33 Timer _t;
kimberlylie99 0:b97c07227845 34 Timeout _tout;
kimberlylie99 0:b97c07227845 35 int _distance;
kimberlylie99 0:b97c07227845 36 float _updateSpeed;
kimberlylie99 0:b97c07227845 37 int start;
kimberlylie99 0:b97c07227845 38 int end;
kimberlylie99 0:b97c07227845 39 volatile int done;
kimberlylie99 0:b97c07227845 40 void (*_onUpdateMethod)(int);
kimberlylie99 0:b97c07227845 41 void _startT(void);
kimberlylie99 0:b97c07227845 42 void _updateDist(void);
kimberlylie99 0:b97c07227845 43 void _startTrig(void);
kimberlylie99 0:b97c07227845 44 float _timeout;
kimberlylie99 0:b97c07227845 45 int d;
kimberlylie99 0:b97c07227845 46 };
kimberlylie99 0:b97c07227845 47 #endif