I am a newbie and am trying to modify the analogin example. When declaring analog sensor variables, is there a quicker (shorter) way of doing it than the below? thanks in advance, F
int sensor1 = 0; // first analog sensor
int sensor2 = 0; // second analog sensor
int sensor3 = 0; // etc
int sensor4 = 0;
int sensor5 = 0;
int sensor6 = 0;
int sensor7 = 0;
int sensor8 = 0;
int sensor9 = 0;
int sensor10 = 0;
int sensor11 = 0;
int sensor12 = 0;
int sensor13 = 0;
int sensor14 = 0;
int sensor32 = 0;
int sensoretc = 0;
int inByte = 0; // incoming serial byte
int sensorArray[21]={1,2,3,4,5,6,7,8,9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; // 20 analog sensors
int i;
for (i = 0; i < 20; i = i + 1) {
Serial.println(sensorArray*); // check each sensor up to 20 and give the values to the serial print* } I cant test it myself - my arduino hasnt arrived in the mail yet!
Serial.println(sensorArray [ i ] ); // check each sensor up to 20 and give the values to the serial
Note: The code you posted does not actually read each sensor. It only sends the values to Serial. To read sensors you need to call either the digitalRead or the analogRead function.
One very minor issue...
int sensorArray[20]={1,2,3,4,5,6,7,8,9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}; // 20 analog sensors
You declared the array a bit larger than it needs to be. Don't make the opposite mistake (making the array too small)!