Hallo,
ich habe wieder mal ein kleines Problem und komme nicht auf die Lösung.
Ich möchte mit der non blocking Dallas Bibliothek <NonBlockingDallas.h> 4 Werte einlesen. Es ist soweit alles verdrahtet, Widerstand eingelötet, mit dem Beispiel funktioniert es auch.
Aber wie kann ich die eingelesenen Temperaturen verwenden oder verwendbaren Variablen zuweisen? Irgendwie stehe ich auf dem Schlauch.
Das Beispiel läuft:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <NonBlockingDallas.h> //Include the NonBlockingDallas library
#define ONE_WIRE_BUS 6 //PIN of the Maxim DS18B20 temperature sensor
#define TIME_INTERVAL 1000 //Time interval among sensor readings [milliseconds]
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature dallasTemp(&oneWire);
NonBlockingDallas sensorDs18b20(&dallasTemp); //Create a new instance of the NonBlockingDallas class
void setup() {
Serial.begin(9600);
while (!Serial)
;
//Initialize the sensor passing the resolution, unit of measure and reading interval [milliseconds]
sensorDs18b20.begin(NonBlockingDallas::resolution_12, NonBlockingDallas::unit_C, TIME_INTERVAL);
//Callbacks
sensorDs18b20.onIntervalElapsed(handleIntervalElapsed);
sensorDs18b20.onTemperatureChange(handleTemperatureChange);
//Call the following function if you want to request the temperature without waiting for TIME_INTERVAL to elapse
//The temperature value will then be provided with the onTemperatureChange callback when ready
sensorDs18b20.requestTemperature();
}
void loop() {
sensorDs18b20.update();
/*
* EVEN THOUGH THE SENSOR CONVERSION TAKES UP TO 750ms
* THE NonBlockingDallas LIBRARY WAITS FOR THE CONVERSION
* WITHOUT BLOCKING THE loop AND CALLS THE CALLBACKS
* WHEN THE TEMPERATURE VALUE IS READY
*/
}
//Invoked at every sensor reading (TIME_INTERVAL milliseconds)
void handleIntervalElapsed(float temperature, bool valid, int deviceIndex){
Serial.print("Sensor ");
Serial.print(deviceIndex);
Serial.print(" temperature: ");
Serial.print(temperature);
Serial.println(" °C");
/*
* DO SOME AMAZING STUFF WITH THE TEMPERATURE
*/
}
die Werte werden alle 4 angezeigt. Aber wie weise ich sie zu?
Danke schon mal vorab
Gruß