How to do the same in loop?

Is it possible to build loop for this:

    DS18B20.requestTemperaturesByAddress(tP200);
    t = DS18B20.getTempC(tP200);
    if (t > -100) {tempString += sP200 + "=" + t + "&";}
    
    DS18B20.requestTemperaturesByAddress(TEST);
    t = DS18B20.getTempC(TEST);
    if (t > -100) { tempString += sTEST + "=" + t + "&"; }

    DS18B20.requestTemperaturesByAddress(tP5);
    t = DS18B20.getTempC(tP5);
    if (t > -100) { tempString += sP5 + "=" + t + "&"; }

    DS18B20.requestTemperaturesByAddress(tG5);
    t = DS18B20.getTempC(tG5);
    if (t > -100) { tempString += sG5 + "=" + t + "&"; }

    DS18B20.requestTemperaturesByAddress(tG10);
    t = DS18B20.getTempC(tG10);
    if (t > -100) { tempString += sG10 + "=" + t + "&"; }

Full code are here:

#include <OneWire.h>
#include <DallasTemperature.h>

//DEKLARACJA ADRESÓW DS18B20
DeviceAddress tP200 = {0x28, 0xFF, 0x4F, 0xEA, 0xB3, 0x16, 0x03, 0x60};
DeviceAddress tP5 =   {0x28, 0xFF, 0x32, 0x70, 0xB3, 0x16, 0x05, 0xC6};
DeviceAddress tG5 =   {0x28, 0xFF, 0x5F, 0x8D, 0xB3, 0x16, 0x04, 0x89};
DeviceAddress tG10 =  {0x28, 0xFF, 0xC0, 0x30, 0xB5, 0x16, 0x05, 0xD2};
DeviceAddress tG20 =  {0x28, 0xFF, 0x01, 0x0B, 0xB5, 0x16, 0x05, 0xE1};
DeviceAddress tG50 =  {0x28, 0xFF, 0xD4, 0xE6, 0xB3, 0x16, 0x03, 0xB5};
DeviceAddress tG100 = {0x28, 0xFF, 0xC1, 0xE8, 0xB3, 0x16, 0x03, 0x0E};
DeviceAddress tG200 = {0x28, 0xFF, 0x92, 0xC3, 0xB3, 0x16, 0x05, 0xEC};
DeviceAddress tS =    {0x10, 0xED, 0xDF, 0x39, 0x01, 0x08, 0x00, 0xAF};
DeviceAddress TEST =  {0x10, 0xCD, 0x0D, 0x39, 0x01, 0x08, 0x00, 0xC4};

//DEKLARACJA ADRESÓW JAKO String

String sP200 =  "28FF4FEAB3160360";
String sP5 =  "28FF3270B31605C6";
String sG5 =  "28FF5F8DB3160489";
String sG10 = "28FFC030B51605D2";
String sG20 = "28FF010BB51605E1";
String sG50 = "28FFD4E6B31603B5";
String sG100 =  "28FFC1E8B316030E";
String sG200 =  "28FF92C3B31605EC";
String sS =   "10EDDF39010800AF";
String sTEST =  "10CD0D39010800C4";

#define ONE_WIRE_BUS 5

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature DS18B20(&oneWire);


void setup() {
    Serial.begin(74880);

}

void loop() {
float t;
    String tempString = "?";


    
    DS18B20.requestTemperaturesByAddress(tP200);
    t = DS18B20.getTempC(tP200);
    if (t > -100) {tempString += sP200 + "=" + t + "&";}
    
    DS18B20.requestTemperaturesByAddress(TEST);
    t = DS18B20.getTempC(TEST);
    if (t > -100) { tempString += sTEST + "=" + t + "&"; }

    DS18B20.requestTemperaturesByAddress(tP5);
    t = DS18B20.getTempC(tP5);
    if (t > -100) { tempString += sP5 + "=" + t + "&"; }

    DS18B20.requestTemperaturesByAddress(tG5);
    t = DS18B20.getTempC(tG5);
    if (t > -100) { tempString += sG5 + "=" + t + "&"; }

    DS18B20.requestTemperaturesByAddress(tG10);
    t = DS18B20.getTempC(tG10);
    if (t > -100) { tempString += sG10 + "=" + t + "&"; }

    
    tempString.remove(tempString.length()-1);
    Serial.println(tempString);

}

Now I have:

DS18B20.requestTemperaturesByAddress(tP200);
t = DS18B20.getTempC(tP200);
if (t > -100) {tempString += sP200 + "=" + t + "&";}

DS18B20.requestTemperaturesByAddress(TEST);
t = DS18B20.getTempC(TEST);
if (t > -100) { tempString += sTEST + "=" + t + "&"; }

DS18B20.requestTemperaturesByAddress(tP5);
t = DS18B20.getTempC(tP5);
if (t > -100) { tempString += sP5 + "=" + t + "&"; }

DS18B20.requestTemperaturesByAddress(tG5);
t = DS18B20.getTempC(tG5);
if (t > -100) { tempString += sG5 + "=" + t + "&"; }

DS18B20.requestTemperaturesByAddress(tG10);
t = DS18B20.getTempC(tG10);
if (t > -100) { tempString += sG10 + "=" + t + "&"; }

I ask if it possible to build something like this:

do {
    DS18B20.requestTemperaturesByAddress(tP200);
    t = DS18B20.getTempC(tP200);
    if (t > -100) {tempString += sP200 + "=" + t + "&";}
    } WHILE (CONDITION)

Delta_G:
You'll need an array holding pointers

What's that mean? Can you give any example? And another question: it will be better or it should stay as it is?

You can build a function that takes parameters, such as the address of the device to get the temperature from, and the String instance to use.

Call that function many times. Not everything involves a loop. Very few things use a do/while loop.

Delta_G:
That's a question for you. You have to define "better". BY what metrics?

Question is not for me but for this who are good in coding, I ask what is better for clear and fast code

Delta_G:
See the red parts? They're different each time. So you need some way to index through those. The easiest way would be to put whatever tP200 and TEST, and the others are into an array so that you can use a for loop.

I know what to do but I don't know how... I don't know how create array of my arrays (DeviceAddress)

better is the way which will choose hi level Arduino programer

I will give up, thanks for trying help :slight_smile:

OP: Google "C++ tutorial". Do a C++ tutorial. This will cover arrays, structs, other basic parts of the C++ programming language. Then you will have a better idea what facilities are present in the language to enable you to write the code you want.
[/quote]

in answer to your question, however:

class SensorAddress {
  public:
  const byte address;
  const char *name;
  SensorAddress(byte address, char *name) :  address(address), name(name) {}
};

SensorAddress sensorAddress[] = {
  SensorAddress(tP200, "t P200"),
  SensorAddress(sTEST, "s TEST"),
  SensorAddress(tP5, "t P5"),
  SensorAddress(sG5, "s G5"),
  SensorAddress(sG10, "s G10")
};

void loop() {
  // …

  for(int i = 0; i<sizeof(sensorAddress)/sizeof(*sensorAddress); i++) {
    DS18B20.requestTemperaturesByAddress(sensorAddress[i].address);
    t = DS18B20.getTempC(sensorAddress[i].address);
    if (t > -100) {tempString += sensorAddress[i].name + "=" + t + "&";}
  }

  // …
}

Thanks you PaulMurrayCbr for lerning me something new! You are awesome.