diff --git a/README.md b/README.md index 5f1a4f2..ee2b1b4 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ void loop() ```ino #include -HCSR04 hc(2,new int[6]{5,6,7,8,9,10});//initialisation class HCSR04 (trig pin , echo pin) +HCSR04 hc(2,new int[6]{5,6,7,8,9,10},6);//initialisation class HCSR04 (trig pin , echo pins, number of sensors) void setup() { Serial.begin(9600); } diff --git a/examples/HCSR04_multi/HCSR04_multi.ino b/examples/HCSR04_multi/HCSR04_multi.ino index 52903a6..1cb3716 100644 --- a/examples/HCSR04_multi/HCSR04_multi.ino +++ b/examples/HCSR04_multi/HCSR04_multi.ino @@ -1,6 +1,6 @@ #include -HCSR04 hc(2,new int[6]{5,6,7,8,9,10});//initialisation class HCSR04 (trig pin , echo pin) +HCSR04 hc(2,new int[6]{5,6,7,8,9,10},6);//initialisation class HCSR04 (trig pin , echo pin, number of sensor) void setup() { Serial.begin(9600); } diff --git a/library.properties b/library.properties index d9e7c58..3c1ad13 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=HCSR04 ultrasonic sensor -version=2.0.0 +version=2.0.1 author=gamegine maintainer=gamegine sentence=Allows an Arduino board to use HCSR04 module. diff --git a/src/HCSR04.cpp b/src/HCSR04.cpp index 0339e96..905bb2d 100644 --- a/src/HCSR04.cpp +++ b/src/HCSR04.cpp @@ -1,19 +1,20 @@ #include "HCSR04.h" ////////////////////////////////////consttruct/destruct -void HCSR04::init(int out,int echo[]) +void HCSR04::init(int out,int echo[],int n) { this->out = out; this->echo = echo; + this->n = n; pinMode(this->out, OUTPUT); - for(int i=0;iecho[i], INPUT); } + for(int i=0;iecho[i], INPUT); } } -HCSR04::HCSR04(int out,int echo){this->init(out,new int[1]{echo});} -HCSR04::HCSR04(int out,int echo[]){this->init(out,echo);} +HCSR04::HCSR04(int out,int echo){this->init(out,new int[1]{echo},1);} +HCSR04::HCSR04(int out,int echo[],int n){this->init(out,echo,n);} HCSR04::~HCSR04() { ~this->out; delete[] this->echo; + ~this->n; } ///////////////////////////////////////////////////dist float HCSR04::dist(int n) const diff --git a/src/HCSR04.h b/src/HCSR04.h index fa6f4ac..cbc03e5 100644 --- a/src/HCSR04.h +++ b/src/HCSR04.h @@ -3,13 +3,14 @@ class HCSR04 { public: HCSR04(int out,int echo); //initialisation class HCSR04 (trig pin , echo pin) - HCSR04(int out,int echo[]); //initialisation class HCSR04 (trig pin , echo pin) + HCSR04(int out,int echo[],int n); //initialisation class HCSR04 (trig pin , echo pin) ~HCSR04(); //destructor float dist() const; //return curent distance of element 0 float dist(int n) const; //return curent distance of element 0 private: - void init(int out,int echo[]); //for constructor + void init(int out,int echo[],int n); //for constructor int out; //out pin int *echo; //echo pin list + int n; //number of el };