Skip to content

Commit

Permalink
Update example
Browse files Browse the repository at this point in the history
  • Loading branch information
hibikiledo committed Nov 6, 2016
1 parent 0281107 commit 62c415b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 72 deletions.
80 changes: 10 additions & 70 deletions README.md
Expand Up @@ -89,36 +89,6 @@ void loop() {

---

```cpp
bool measureTemperature();
```
#### Summary
Tell the sensor to perform temperature acquisition.

#### Parameters
None

#### Return Value
- true - the operation is successful
- false - an error occurs. use `getErrorCode()` to get an error code. [More info](#error-codes)

---

```cpp
bool measureHumidity();
```
#### Summary
Tell the sensor to perform humidity acquisition.

#### Parameters
None

#### Return Value
- true - the operation is successful
- false - an error occurs. use `getErrorCode()` to get an error code. [More info](#error-codes)

---

```cpp
bool measure();
```
Expand Down Expand Up @@ -192,6 +162,15 @@ CRC validation failed. This happends when data transmitted from the sensor is re
// Create an instance of sensor
AM2320 sensor;

void setup() {
// enable serial communication
// Include library into the sketch
#include <AM2320.h>
#include <Wire.h>

// Create an instance of sensor
AM2320 sensor;

void setup() {
// enable serial communication
Serial.begin(115200);
Expand All @@ -201,13 +180,11 @@ void setup() {

void loop() {

// measure both temperature and humidity at once.
// sensor.measure() returns boolean value
// - true indicates measurement is completed and success
// - false indicates that either sensor is not ready or crc validation failed
// use getErrorCode() to check for cause of error.
if (sensor.measure()) {
Serial.println("Measuring both temperature and humidity at once ..");
Serial.print("Temperature: ");
Serial.println(sensor.getTemperature());
Serial.print("Humidity: ");
Expand All @@ -221,44 +198,7 @@ void loop() {
}
}

// measure only temperature
// sensor.measureTemerature() returns boolean value
// - true indicates measurement is completed and success
// - false indicates that either sensor is not ready or crc validation failed
// use getErrorCode() to check for cause of error.
if (sensor.measureTemperature()) {
Serial.println("Measuring only temperature ..");
Serial.print("Temperature: ");
Serial.println(sensor.getTemperature());
}
else { // error has occured
int errorCode = sensor.getErrorCode();
switch (errorCode) {
case 1: Serial.println("ERR: Sensor is not online"); break;
case 2: Serial.println("ERR: CRC validation failed."); break;
}
}

// measure only humidity
// sensor.measureHumidity() returns boolean value
// - true indicates measurement is completed and success
// - false indicates that either sensor is not ready or crc validation failed
// use getErrorCode() to check for cause of error.
if (sensor.measureHumidity()) {
Serial.println("Measuring only humidity ..");
Serial.print("Humidity: ");
Serial.println(sensor.getHumidity());
}
else { // error has occured
int errorCode = sensor.getErrorCode();
switch (errorCode) {
case 1: Serial.println("ERR: Sensor is not online"); break;
case 2: Serial.println("ERR: CRC validation failed."); break;
}
}

delay(1000);

delay(500);
}
```

Expand Down
3 changes: 1 addition & 2 deletions examples/AM2320-Example/AM2320-Example.ino
Expand Up @@ -17,7 +17,6 @@

// Include library into the sketch
#include <AM2320.h>
#include <Wire.h>

// Create an instance of sensor
AM2320 sensor;
Expand All @@ -44,7 +43,7 @@ void loop() {
else { // error has occured
int errorCode = sensor.getErrorCode();
switch (errorCode) {
case 1: Serial.println("ERR: Sensor is not online"); break;
case 1: Serial.println("ERR: Sensor is offline"); break;
case 2: Serial.println("ERR: CRC validation failed."); break;
}
}
Expand Down

0 comments on commit 62c415b

Please sign in to comment.