Skip to content

Commit

Permalink
add number of sensor in constructor multi
Browse files Browse the repository at this point in the history
  • Loading branch information
gamegine committed May 2, 2018
1 parent d28f90d commit c7a594c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ void loop()
```ino
#include <HCSR04.h>
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); }
Expand Down
2 changes: 1 addition & 1 deletion examples/HCSR04_multi/HCSR04_multi.ino
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <HCSR04.h>

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); }
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
11 changes: 6 additions & 5 deletions src/HCSR04.cpp
Original file line number Diff line number Diff line change
@@ -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;i<sizeof(echo);i++)
{ pinMode(this->echo[i], INPUT); }
for(int i=0;i<n;i++){ pinMode(this->echo[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
Expand Down
5 changes: 3 additions & 2 deletions src/HCSR04.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
};

0 comments on commit c7a594c

Please sign in to comment.