Re: Arduino - zpřehlednění rozsáhleho kódu
Napsal: 17 bře 2020, 19:18
				
				Ahoj, asi bych zkusil klíče preprocesor, direktivy překladače, podmíněný překlad, direktivy #if, #ifdef, #ifndef, #else, #elif a #endif
			České fórum pro všechny nadšence do Arduina a dalších technologií.
https://forum.hwkitchen.cz/
Kód: Vybrat vše
#if (BME == 1)
   #include <Adafruit_Sensor.h>     // Adafruit Unified Sensor 1.1.1 https://github.com/adafruit/Adafruit_Sensor
   #include <Adafruit_BME280.h>     // Adafruit BME280 Library 2.0.1 https://github.com/adafruit/Adafruit_BME280_Library
#endif
#if (HDC == 1)
   #include <HDC2080.h>             // Lime Labs HDC2080 1.0.1 https://github.com/lime-labs/HDC2080-Arduino
#endif
Kód: Vybrat vše
#if (BME == 1)
   Adafruit_BME280 bme280;                       
#endif
#if (HDC == 1)
   HDC2080 sensorHDC(ADDR_HDC2080);
#endif
Kód: Vybrat vše
// Připojení k BME280
#if (BME == 1)
  if (!bme280.begin(BME280_ADRESA)) {
     Serial.println("Senzor BME280 nenalezen overit pripojeni !");
     while (1) {}
     } 
     Serial.println("BME280 OK");
#endif
// Připojení k HDC2080 + nastaveni
#if (HDC == 1)
   sensorHDC.begin();
   sensorHDC.reset();// Begin with a device reset
   // Configure Measurements
   sensorHDC.setMeasurementMode(TEMP_AND_HUMID);  // Set measurements to temperature and humidity
   sensorHDC.setRate(ONE_MINS);                     // Set measurement every minute
   sensorHDC.setTempRes(FOURTEEN_BIT);
   sensorHDC.setHumidRes(FOURTEEN_BIT);
   //begin measuring
   sensorHDC.triggerMeasurement(); 
   Serial.println("HDC2080 OK");
#endif
Kód: Vybrat vše
//---------------------------------------------------------------------------------  
//                    T - TEPLOTA z BME/HDC
//--------------------------------------------------------------------------------- 
  void VyctiTeplotu(){
     
#if (BME == 1 && HDC == 1)     
     T = (sensorHDC.readTemp() + bme280.readTemperature()) / 2;                         
#endif
#if (BME == 1 && HDC == 0)     
     T = bme280.readTemperature();                         
#endif
#if (BME == 0 && HDC == 1)     
     T =  sensorHDC.readTemp();                         
#endif
     if(ladeni == 1) {                                       
        Serial.print("Teplota : ");
        Serial.print(T);
        Serial.println(" stupnu Celsia");
     }
  }