Add a number to a variable name.

I have a little project I'm working on to monitor temperatures on 2 different temp sensors. I have a piece of code that looks like the following to log the highest and lowest temp and humidity so I can graph it later.

if(DHT11.humidity<tHumMin) { tHumMin=DHT11.humidity; }
if(DHT11.humidity>tHumMax) { tHumMax=DHT11.humidity; }
if(DHT11.temperature<tTempMin) { tTempMin=DHT11.temperature; }
if(DHT11.temperature>tTempMax) { tTempMax=DHT11.temperature; }

My question is, is there a way to do something like this:

for(i=1;i<3;i++) {
  if(DHT11.humidity<(tHumMin+i)) { (tHumMin+i)=DHT11.humidity; }
  if(DHT11.humidity>(tHumMax+i)) { (tHumMax+i)=DHT11.humidity; }
  if(DHT11.temperature<(tTempMin+i)) { (tTempMin+i)=DHT11.temperature; }
  if(DHT11.temperature>(tTempMax+i)) { (tTempMax+i)=DHT11.temperature; }
};

To avoid confusion, I want to turn tHumMin into tHumMin1 or tHumMin2 based on i from the for loop. I've declared all the variables and tried a few different things but I can't seem to figure out how to do this.

What you seek is called an "array"...

http://arduino.cc/it/Reference/Array

https://www.google.com/search?q=arduino+array

Ah, I didn't even think of using an array. That's much smarter than creating all those variables. I'll rework my code and let you know how it goes. Thanks :slight_smile: