Skip to content

Commit e078f81

Browse files
authored
Merge pull request #9 from DrGFreeman/in_work
Adding SharpDistSensorArray example
2 parents 2b86f8d + d9ffdb3 commit e078f81

8 files changed

Lines changed: 91 additions & 16 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2017
3+
Copyright (c) 2017-2018
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# SharpDistSensor
22
A library for the Arduino IDE that helps interface with Sharp analog distance sensors.
33

4-
Version 1.2.0
4+
Version 1.3.0
55
[![Build Status](https://travis-ci.org/DrGFreeman/SharpDistSensor.svg?branch=master)](https://travis-ci.org/DrGFreeman/SharpDistSensor)
66
By Julien de la Bruère-Terreault (drgfreeman@tuta.io)
77

@@ -16,7 +16,8 @@ For different accuracy, range, sensor model or units, different coefficients may
1616
The distance output is filtered using real-time median filtering (sliding window of ajustable size). The MedianFilter class from the following library is used: https://github.com/daPhoosa/MedianFilter.
1717

1818
## Examples
19-
Four example sketches are provided with the library:
19+
Five example sketches are provided with the library:
20+
2021
* _SharpDistSensorBasic.ino_
2122
This example shows how to use the library with the default calibration function for the Sharp GP2Y0A60SZLF 5V sensor.
2223

@@ -30,6 +31,9 @@ This example shows how to use the library with a custom, user defined polynomial
3031
* _SharpDistSensorCustomPower.ino_
3132
This example shows how to use the library with a custom, user defined power calibration function.
3233

34+
* _SharpDistSensorArray.ino_
35+
This example shows how to use the library with an array of multiple sensors.
36+
3337
## Library Reference
3438
* `SharpDistSensor(const byte pin, const byte size = 1)`
3539
Constructor: `pin` is the analog pin to which the sensor is connected, `size` is the size of the median filter window and should be an odd positive integer (default = 1 = no filtering).
@@ -67,6 +71,7 @@ Model | Units | C0 | C1 | C2 | C3 | C4 | C5 | valMin | valMax
6771
This library has been designed so that it is easy to add sensor models. Contributions are therefore welcome. Adding models to the library can be done by either submitting a pull request or providing me the proposed fit function and associated calibration data by email so I can add it myself. Thank you for contributing!
6872

6973
## Version history
74+
* 1.3.0 (2018-05-20): Added SharpDistSensorArray example.
7075
* 1.2.0 (2017-05-10): Added GP2Y0A710K0F_5V_DS model.
7176
* 1.1.1 (2017-05-01): Clarified comments and fixed typos in examples, improved README.
7277
* 1.1.0 (2017-04-05): Added support of power fit functions.
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
SharpDistSensorArray.ino
3+
4+
Source: https://github.com/DrGFreeman/SharpDistSensor
5+
6+
MIT License
7+
8+
Copyright (c) 2018 Julien de la Bruere-Terreault <drgfreeman@tuta.io>
9+
Permission is hereby granted, free of charge, to any person obtaining a copy
10+
of this software and associated documentation files (the "Software"), to deal
11+
in the Software without restriction, including without limitation the rights
12+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
copies of the Software, and to permit persons to whom the Software is
14+
furnished to do so, subject to the following conditions:
15+
16+
The above copyright notice and this permission notice shall be included in all
17+
copies or substantial portions of the Software.
18+
19+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25+
SOFTWARE.
26+
*/
27+
28+
/*
29+
This example shows how to use the SharpDistSensor library with an array of
30+
multiple sensors.
31+
32+
See the library README for how to use pre-defined sensor models or custom fit
33+
functions.
34+
*/
35+
36+
#include <SharpDistSensor.h>
37+
38+
// Define the number of sensors in the array as a constant
39+
const byte nbSensors = 2;
40+
41+
// Window size of the median filter (odd number, 1 = no filtering)
42+
const byte medianFilterWindowSize = 5;
43+
44+
// Define the array of SharpDistSensor objects
45+
SharpDistSensor sensorArray[] = {
46+
SharpDistSensor(A1, medianFilterWindowSize), // First sensor using pin A1
47+
SharpDistSensor(A2, medianFilterWindowSize), // Second sensor using pin A2
48+
// Add as many sensors as required
49+
};
50+
51+
// Alternatively, the array can be defined this way
52+
// SharpDistSensor sensorArray[nbSensors] = {{A1, medianFilterWindowSize},
53+
// {A2, medianFilterWindowSize}};
54+
55+
// Define an array of integers that will store the measured distances
56+
uint16_t distArray[nbSensors];
57+
58+
void setup() {
59+
// Set some parameters for each sensor in array
60+
for (byte i = 0; i < nbSensors; i++) {
61+
sensorArray[i].setModel(SharpDistSensor::GP2Y0A710K0F_5V_DS); // Set sensor model
62+
// Set other parameters as required
63+
}
64+
}
65+
66+
void loop() {
67+
// Read distance for each sensor in array into an array of distances
68+
for (byte i = 0; i < nbSensors; i++) {
69+
distArray[i] = sensorArray[i].getDist();
70+
}
71+
}

examples/SharpDistSensorBasic/SharpDistSensorBasic.ino

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ SOFTWARE.
2727

2828
/*
2929
This example shows how to use the SharpDistSensor library to continuously
30-
read the sensor and display the analog value and the corrseponding distance
31-
in mm.
30+
read the sensor and display the measured distance in mm to the serial monitor.
3231
3332
The library default values corresponding to the Sharp GP2Y0A60SZLF 5V sensor
3433
are used.
@@ -43,10 +42,10 @@ fit functions.
4342
const byte sensorPin = A0;
4443

4544
// Window size of the median filter (odd number, 1 = no filtering)
46-
const byte mediumFilterWindowSize = 5;
45+
const byte medianFilterWindowSize = 5;
4746

4847
// Create an object instance of the SharpDistSensor class
49-
SharpDistSensor sensor(sensorPin, mediumFilterWindowSize);
48+
SharpDistSensor sensor(sensorPin, medianFilterWindowSize);
5049

5150

5251
void setup() {

examples/SharpDistSensorByModel/SharpDistSensorByModel.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ constants or for how to use custom defined fit functions.
3838
const byte sensorPin = A0;
3939

4040
// Window size of the median filter (odd number, 1 = no filtering)
41-
const byte mediumFilterWindowSize = 5;
41+
const byte medianFilterWindowSize = 5;
4242

4343
// Create an object instance of the SharpDistSensor class
44-
SharpDistSensor sensor(sensorPin, mediumFilterWindowSize);
44+
SharpDistSensor sensor(sensorPin, medianFilterWindowSize);
4545

4646
void setup() {
4747
Serial.begin(9600);

examples/SharpDistSensorCustomPoly/SharpDistSensorCustomPoly.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ for different sensors, units, calibration or range.
4141
const byte sensorPin = A0;
4242

4343
// Window size of the median filter (odd number, 1 = no filtering)
44-
const byte mediumFilterWindowSize = 5;
44+
const byte medianFilterWindowSize = 5;
4545

4646
// Create an object instance of the SharpDistSensor class
47-
SharpDistSensor sensor(sensorPin, mediumFilterWindowSize);
47+
SharpDistSensor sensor(sensorPin, medianFilterWindowSize);
4848

4949
/*
5050
* Polynomial fit curve coefficients C0 to C5 in relation:

examples/SharpDistSensorCustomPower/SharpDistSensorCustomPower.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ using custom power fit curve and range.
3737
const byte sensorPin = A0;
3838

3939
// Window size of the median filter (odd number, 1 = no filtering)
40-
const byte mediumFilterWindowSize = 5;
40+
const byte medianFilterWindowSize = 5;
4141

4242
// Create an object instance of the SharpDistSensor class
43-
SharpDistSensor sensor(sensorPin, mediumFilterWindowSize);
43+
SharpDistSensor sensor(sensorPin, medianFilterWindowSize);
4444

4545
/* Set the power fit curve coefficients and range
4646
* C and P: Coefficients in Distance = C*A^P relation

library.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name=SharpDistSensor
2-
version=1.2.0
3-
author=Julien de la Bruere-Terreault (drgfreeman@tuta.io)
4-
maintainer=Julien de la Bruere-Terreault (drgfreeman@tuta.io)
2+
version=1.3.0
3+
author=Julien de la Bruere-Terreault, drgfreeman@tuta.io
4+
maintainer=Julien de la Bruere-Terreault, drgfreeman@tuta.io
55
sentence=Sharp analog distance sensor library
66
paragraph=This is a library for the Arduino IDE that helps interface with Sharp IR analog distance sensors. It supports polynomial and power fit functions as well as real-time median filtering (sliding window of ajustable size).
77
category=Sensors

0 commit comments

Comments
 (0)