Assigning values to multiple analog reads

Hi,

I'm using an Arduino UNO to measure resistance across a PTC thermistor. I'm new to programming and I'm not sure how to continuously assign analogread values to a pin.

This is my set up code and I would like a for loop to iterate through analogReads assigned to each pin so that for example I could get reading1 = analogRead(THERMISTORPIN1);

// Voltage division circuit w. 1k Ohm resistor
#define SERIESRESISTOR 1000
#define THERMISTORPIN1 A0
#define THERMISTORPIN2 A1
#define THERMISTORPIN3 A2
#define THERMISTORPIN4 A3

void setup(void) {
Serial.begin(9600);
}

void loop(void) {
float reading;
float resistance;

Thanks for your help!

As a person new to programming, you could create 4 variables, reading1, reading2, reading3, reading4 and then just use them for each of your pins.

The more common way would be to use arrays which are very handy for this sort of thing

int pin[] = {A0,A1,A2,A3};
const int pinCount = sizeof(pin) / sizeof(pin[0]);

int reading[pinCount];

void setup(void) {
  Serial.begin(9600);
}

void loop(void) {
  for( int i=0; i<pinCount; ++i ) {
    reading[i] = analogRead(pin[i]);
    // do whatever
  }
}

Thanks a lot I'm definitely gonna use arrays!

You created a useful identity and then discarded it. #define THERMISTORPIN1 was a great idea, now you know what the pin is used for. But 'reading1' doesn't say that it is thermistor. After you take the reading, it's the 'reading1' value that you deal with. It would be better as thermistorReading1, or something like that. Same with 'resistance'... resistance of what? Often programs grow in size as features are added, and it's better to describe things completely so there is no confusion later.

It's not a big deal, but I see it happen too many times... someone starts out with great definitions and then forgets to carry them forward into the code completely.