//read multiple analog inputs and send their pin number and their value out the serial port #define NumSensors 2 //define creates a constant that can be used to initalize other variables, notice no = sign or ; int led = 13;//create a variable to hold the pin number the LED is connected to int values[NumSensors];//create an array, a list, to hold the values of each sensor int oldValues[NumSensors];//create an array to hold the old values of each sensor void setup(){ for(int i = 0; i < NumSensors; i++){//initalize number of pins the sensors are connected to using a for loop pinMode(i, INPUT); } Serial.begin(9600);//initalize serial communication at 9600baud startBlink();//blink an LED at the begining of the program } void loop(){ for(int i = 0; i < NumSensors; i++){//use a for loop to read thru the number of pins the sensors are connected to values[i] = analogRead(i);//read the sensor and store the value in the corrosponding array index values[i] /= 2;//divide the sensor value by 2 to get rid of flutter in the last bit of the value, this reduces the resolution, but gives a more stable reading if(values[i] != oldValues[i]){//compare the sensor's current value to the old value in the same index of the oldValues array, if they are not equal(!=) then.... Serial.print(i);//send the sensor's index out the serial port Serial.print(" ");//send a space out the out the serial port Serial.print(values[i]);//send the sensor's value out the the serial port Serial.print("\n");//send a new line (\n) out the serial port oldValues[i] = values[i];//store the current sensor reading in the corrosponding index of the oldValues array } } delay(10);//wait 10ms } void startBlink(){ pinMode(led, OUTPUT); for(int i = 0; i < 4; i++){ digitalWrite(led, HIGH); delay(250); digitalWrite(led, LOW); delay(250); } }