Gbertaz / NonBlockingDallas

Arduino library for the DS18B20 temperature sensor. Avoid blocking the sketch while reading the sensor.
MIT License
11 stars 4 forks source link

Measure 5 sensors #4

Closed Dezolator99 closed 2 years ago

Dezolator99 commented 2 years ago

I have 6 DS18B20 sensors, how do I get the temperature read from each sensor to be assigned to a different variable. Semzors: Sensor1 0x28, 0xB5, 0x3B, 0x49, 0xF6, 0x73, 0x3C, 0xD7 Sensor2 0x28, 0x17, 0xC4, 0x49, 0xF6, 0xA1, 0x3C, 0xE5 Sensor3 0x28, 0x4C, 0xF4, 0x49, 0xF6, 0xA8, 0x3C, 0x05 Sensor4 0x28, 0xF2, 0x28, 0x49, 0xF6, 0x39, 0x3C, 0x69 Sensor5 0x28, 0xDD, 0xB2, 0x49, 0xF6, 0x17, 0x3C, 0xEC Sensor6 0x28, 0x84, 0xD7, 0x96, 0xF0, 0x01, 0x3C, 0x9B Variables: float temp1 float temp2 float temp3 float temp4 float temp5 float temp6

I need each sensor to always write the temperature in its variable.

Gbertaz commented 2 years ago

Hi. In the body of the callback function you can assign the temperature to its respective variable according to the sensor index.

For example:


void handleIntervalElapsed(float temperature, bool valid, int deviceIndex){

  switch(deviceIndex){

    case 0:
      temp1 = temperature;
    break;
    case 1:
      temp2 = temperature;
    break;
    case 2:
      temp3 = temperature;
    break;
    case 3:
      temp4 = temperature;
    break;
    case 4:
      temp5 = temperature;
    break;
    case 5:
      temp6 = temperature;
    break;
  }

}