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.
| 23 | // You can recognize sensors by the ID or index. |
| 24 | //*********************************************************** |
| 25 | void 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 |
nothing calls this directly
no test coverage detected