-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTemperatureSensor.ino
67 lines (59 loc) · 1.98 KB
/
TemperatureSensor.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/**
* @brief Example for DS18B20 temperature sensor.
*
* This example measures temperature once per second using the DallasTemperature library.
*
* Copyright 2023 JSC TechMinds
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// The ESP32 boards platform developers decided to treat compiler warnings as errors.
// The OneWire library has a few unused variables, which causes
// this example to fail. The fix is already in OneWire master branch.
// We just have to wait until a new release is made. Until then
// we have disabled this test.
//
// To run this example, comment out the #define TEST_BLACKLISTED line.
//
// Related issues:
// https://github.com/arduino/arduino-cli/issues/2252
// https://github.com/Arduino-CI/arduino_ci/issues/331
// https://github.com/PaulStoffregen/OneWire/issues/74
// https://github.com/PaulStoffregen/OneWire/pull/118
#define TEST_BLACKLISTED
#ifndef TEST_BLACKLISTED
#include <acdu.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
OneWire oneWire(ONEWIRE::PIN_ONEWIRE);
DallasTemperature tempSensor(&oneWire);
void setup() {
// Initialize serial communication.
Serial.begin(115200);
// Initialize temperature sensor.
tempSensor.begin();
}
void loop() {
if (tempSensor.getDeviceCount() == 1) {
tempSensor.requestTemperatures();
Serial.println(tempSensor.getTempCByIndex(0));
} else {
Serial.println("No sensor connected.");
}
delay(3000);
}
#else
void setup() {}
void loop() {}
#endif