MCPcopy Create free account
hub / github.com/SmingHub/Sming / readData

Function readData

samples/Temperature_DS1820/app/application.cpp:25–52  ·  view source on GitHub ↗

DS18S20 example, reading You can connect multiple sensors to a single port (At the moment 4 pcs - it depends on the definition in the library) Measuring time: 1.2 seconds * number of sensors The main difference with the previous version of the demo: - Do not use the Delay function () which is discouraged by the manufacturer of ESP8266 - We can read several sensors Usage: Call Init to setup pin eg.

Source from the content-addressed store, hash-verified

23// You can recognize sensors by the ID or index.
24//***********************************************************
25void readData()
26{
27 if(ReadTemp.MeasureStatus()) {
28 Serial.println(_F("No valid Measure so far! wait please"));
29 return;
30 }
31
32 // the last measurement completed
33 auto sensorCount = ReadTemp.GetSensorsCount();
34 if(sensorCount > 0) {
35 Serial.println(_F("******************************************"));
36 }
37 Serial.println(_F(" Reading temperature DEMO"));
38 // prints for all sensors
39 for(unsigned a = 0; a < sensorCount; a++) {
40 Serial << " T" << a + 1 << " = ";
41 if(ReadTemp.IsValidTemperature(a)) {
42 Serial << ReadTemp.GetCelsius(a) << _F(" Celsius, (") << ReadTemp.GetFahrenheit(a) << _F(" Fahrenheit)")
43 << endl;
44 } else {
45 Serial.println(_F("Temperature not valid"));
46 }
47
48 Serial << _F(" <Sensor id.") << String(ReadTemp.GetSensorID(a), HEX, 32) << '>' << endl;
49 }
50 Serial.println(_F("******************************************"));
51 ReadTemp.StartMeasure(); // next measure, result after 1.2 seconds * number of sensors
52}
53
54} // namespace
55

Callers

nothing calls this directly

Calls 9

MeasureStatusMethod · 0.80
printlnMethod · 0.80
GetSensorsCountMethod · 0.80
IsValidTemperatureMethod · 0.80
GetCelsiusMethod · 0.80
GetFahrenheitMethod · 0.80
GetSensorIDMethod · 0.80
StartMeasureMethod · 0.80
StringClass · 0.50

Tested by

no test coverage detected