Dear Members,
I have 18 sensors which are to be read in 2 arrays (A and B). Each array consists of 9 sensor values (A1,A2...A9). Similarly for array B(B1,B2...B9). For the time being, I don't have sensors so I am testing it with random values.
So I want to fill in the same array in an alternative way. For e.g. First, the array creates 9 values for A like A1,A2,..A9 and after the 9 values are created, the array should create 9 random numbers in the same array for B like B1,B2,...B9 and after B's 9 values are created then it should create 9 values in the same array for A and so on.
Here is my piece of code that I have tried. Please give some guidance on how to do it. Thank you.
float sensor[9];
void setup() {
Serial.begin(9600);
randomSeed(analogRead(0));
}
void loop() {
unsigned long presentMillis = millis();
while (millis() - presentMillis < 500) //500 ms
{
; //wait here
}
presentMillis = millis();
for(int k = 0;k < 9;k++){
if (sizeof(sensor)<9){
sensor[k] = random(0,3.5);
Serial.print("A"+ String(k));
Serial.println(sensor[k]);
//Serial.println(" ");
}
else{
sensor[k] = random(0,3.5);
Serial.print("B"+ String(k));
Serial.println(sensor[k]);
}
}
delay(1000);
//Serial.println();
}