First Draft, serial print change based on distance

Committer:
liam94
Date:
Thu Feb 03 17:43:32 2022 +0000
Revision:
11:5a895d966a3e
Child:
12:b562893a1445
renamed sensor program folder to ultrasonic to make it clearer to read and also removed bitmap library as it wasn't used

Who changed what in which revision?

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