Hello .
I am trying to learn how to use array.
For these:( see Attach)
1.I am using Arduino uno
2.breadboard
3. Three soil moistures sensors connect to A0,A1 ,A2
I am using as an example the following code:
#include <SoftwareSerial.h>
int readPin0 = A0;
int readPin1 = A1;
int readPin2 = A2;
int readValue0 = A0;
int readValue1 = A1;
int readValue2 = A2;
void setup() {
Serial.begin(9600);
}
void loop() {
readValue0 = analogRead(readPin0);
delay(1000);
Serial.print("sensor0 = " );
Serial.println(readValue0);
readValue1 = analogRead(readPin1);
delay(1000);
Serial.print("sensor1 = " );
Serial.println(readValue1);
readValue2 = analogRead(readPin2);
delay(1000);
Serial.print("sensor2 = " );
Serial.println(readValue2);
}
which is working.
I am trying to change the previous code by using arrows
and i change it to the follow:
int array[] = {A0, A1, A2};
int numSensors = 3;
void setup() {
for (int i=0; i<numSensors; i++);
pinMode(array[],INPUT);
for (int i=0; i<numSensors; i++)
analogRead(array[i],LOW);
}
void loop() {
delay(1000);
for (int i=0; i<numSensors; i++)
analogRead(array[i],HIGH);
delay(1000);
}
for (int i=0; i<numSensors; i++)
analogRead(array[i],LOW);
}
When i am trying to compile arduino says :
exit status 1
expected primary-expression before ']' token for pinMode(array[],INPUT);
What i exacluy do i had make wrong ?
Any Help willbe appreciate.