DHT11s read fine from loop, but first one in list doesn't work when in timer...?

I've had a little bit of time this evening to play around with things, and this is where I'm at currently:

I looked into the DHT11 library that relied on interrupts, and it would definitely work awesomely if I just needed to poll one or two DHT11's. However, it looks like it needs a dedicated interrupt pin on the Arduino for each sensor that gets polled, which means that you could realistically poll 3 or maybe 4 sensors on a Mega, since they have 6 timers total. However, eventually I plan on having up to 12 DHT11's attached to my board, so that won't work long-term unfortunately :confused:

So, instead, I just modified my code to use the interrupt to set a flag to have my loop() call the readSensors() function, which works as expected.

I would like to, if possible, have this function execute asynchronously though, because once I get my project fully implemented, it'll have around 30 sensors attached to it, which will all get polled during that function call, so it could potentially put the main loop() on hold for a little while.

I know that normally this probably wouldn't be a big deal, but my plans for this project are to do a home environmental monitor. The readSensors() function I'm planning to have dump the data to the serial line to be picked up by a computer to do logging to a mySQL database at regular intervals, while the main loop() will do stuff like check a water leak sensor, etc. To that end, I'd hate to have a water leak go undetected for 30-45 seconds so that I can record the temperatures upstairs into a database.

I found where you can do a std::async function call in regular C code, but it doesn't look that that's possible in the Arduino IDE? (It throws the error "'async' is not a member of 'std'".) Would this maybe be a job for TimedAction? Arduino Playground - TimedAction Library

Current code:

#include "DHT.h"

#define DHTPIN 9     // what pin we're connected to
#define DHTPIN2 8
#define gled 10
#define rled 11
#define yled 7
int timer1_counter;
volatile int timer_cycle;
volatile boolean pollSensors = false;

#define DHTTYPE DHT11   // DHT 11 

DHT dht(DHTPIN, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);

void setup()
{
  Serial.begin(115200);
  dht.begin();
  dht2.begin();
  pinMode(gled, OUTPUT);
  pinMode(rled, OUTPUT);
  pinMode(yled, OUTPUT);

  // initialize timer1 
  noInterrupts();           // disable all interrupts
  TCCR1A = 0;
  TCCR1B = 0;

  // Set timer1_counter to the correct value for our interrupt interval
  timer1_counter = 3036;   // preload timer 65536-16000000/256/2
  
  TCNT1 = timer1_counter;   // preload timer
  TCCR1B |= (1 << CS12);    // 256 prescaler 
  TIMSK1 |= (1 << TOIE1);   // enable timer overflow interrupt
  interrupts();             // enable all interrupts
}

ISR(TIMER1_OVF_vect)        // interrupt service routine 
{
  TCNT1 = timer1_counter;   // preload timer
  timer_cycle++;
  digitalWrite(gled, digitalRead(gled) ^ 1);
  if (timer_cycle >= 10) {
    timer_cycle = 0;
    digitalWrite(rled, digitalRead(rled) ^ 1);
    pollSensors = true;
  }
}

void loop()
{
  if (pollSensors) {
    readSensors();
  }
}

void readSensors() {
    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    analogWrite(yled,100);
    float h = dht.readHumidity();
    float t = dht.readTemperature();
    h = dht.readHumidity();
    t = dht.readTemperature();
    float h2 = dht2.readHumidity();
    float t2 = dht2.readTemperature();
  
    if (isnan(t)) { t = 0; }
    if (isnan(t2)) { t2 = 0; }
    if (isnan(h)) { h = 0; }
    if (isnan(h2)) { h2 = 0; }

    Serial.print("Humidity 1: "); 
    Serial.print(h);
    Serial.print(" %\t");
    Serial.print("Temperature 1: "); 
    Serial.print(t * 1.8 + 32);
    Serial.println(" *F");
    Serial.print("Humidity 2: "); 
    Serial.print(h2);
    Serial.print(" %\t");
    Serial.print("Temperature 2: "); 
    Serial.print(t2 * 1.8 + 32);
    Serial.println(" *F");
    Serial.println("");
    analogWrite(yled,0);
    pollSensors = false;
}