Skip to content

Commit 52ca51f

Browse files
committed
Add a new Environment.setPin() method. #31
1 parent 4cba8af commit 52ca51f

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

docs/readme.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,13 @@ Initialize the sensor
203203
Using the Grove - Temperature & Humidity Sensor (DHT11)
204204
DHT sensor can read Temperature and Humidity.
205205

206-
### DHTPIN
207-
By default, once you include the library it has been set to digital pin `3`, it can be changed by adding
206+
### setPin()
207+
By default, once you include the library it has been set to digital pin `3`. It can be changed by adding the following line before the call to `begin()`:
208+
208209
```cpp
209-
#define DHTPIN yourPin
210+
Environment.setPin(yourPin);
210211
```
212+
211213

212214
### Initializing the sensor
213215
```cpp

examples/Temp_and_Humidity/Temp_and_Humidity.ino

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//#define DHTPIN 3 // By default its connected to pin D3, it can be changed, define it before the #include of the library
21
#include "Arduino_SensorKit.h"
32

43
//uncomment line below if using DHT20
@@ -7,6 +6,10 @@
76
void setup() {
87
//uncomment line below if using DHT20
98
//Wire.begin();
9+
10+
//uncomment line below if you're connecting your DHT20 to pin a different than 3
11+
//Environment.setPin(4);
12+
1013
Serial.begin(9600);
1114
Environment.begin();
1215
}

src/Arduino_SensorKit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
//Declare component's classes
1414
U8X8_SSD1306_128X64_NONAME_SW_I2C Oled(/* clock=*/ _PIN_SCL, /* data=*/ _PIN_SDA, /* reset=*/ U8X8_PIN_NONE);
15-
DHT Environment(DHTPIN,DHT11);
15+
SensorKit_DHT Environment(3,DHT11);
1616
DHT Environment_I2C(DHT20);
1717
SensorKit_LIS3DHTR Accelerometer;
1818
SensorKit_BMP280 Pressure;

src/Arduino_SensorKit.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,22 @@
1616
#include "Grove_Temperature_And_Humidity_Sensor/DHT.h" // Temp & Humidity
1717
#include "U8x8lib.h" // OLED Display
1818

19-
#ifndef DHTPIN
20-
#define DHTPIN 3
21-
#endif
19+
class SensorKit_DHT;
2220

2321
//Make the declared components from the .cpp to the sketch available
2422
extern U8X8_SSD1306_128X64_NONAME_SW_I2C Oled;
2523
extern SensorKit_LIS3DHTR Accelerometer;
2624
extern SensorKit_BMP280 Pressure;
27-
extern DHT Environment;
25+
extern SensorKit_DHT Environment;
2826
extern DHT Environment_I2C;
29-
#endif
27+
28+
//Subclass DHT
29+
class SensorKit_DHT : public DHT {
30+
public:
31+
SensorKit_DHT(uint8_t pin, uint8_t type) : DHT(pin, type) {};
32+
void setPin(uint8_t pin) {
33+
Environment = SensorKit_DHT(pin, DHT11);
34+
};
35+
};
36+
37+
#endif

0 commit comments

Comments
 (0)