Skip to main content
Update the question
Source Link
Caspert
  • 101
  • 1
  • 1
  • 3

How to store values inside an empty array and get the average integer? [UPDATED QUESTION]

Goodafternoon,

I want to read values form a microphone (microphoneAdafruit MAX9814) ofconnected to the Analog port A0 from Arduino and store the values that are incoming inside an array. 

After the values are storesstored in the array, I want to read out the values and store the average of the hole arraynumber that is repeated most time in a valuevariable. Is this possible and how to achieve this? The size of the array I doesn't know.

I came up with the following:

const int micPin = A0;

 
int soundArray[];soundArray[10];

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(micPin, INPUT); 

}

void loop() {
  // put your main code here, to run repeatedly:
  int micValue = analogRead(micPin);
  Serial.println(micValue, DEC);
  //delay(400);
  
  for (int i = 0; i > 8;10; i++) {
    soundArray[i] = micValue;
    Serial.println(soundArray[i]);
  }
  delay(1000);
  Serial.println("End of for loop");

 
}

The problem now is that a value of the microphone will be repeated 10 times. So I will receive 10 times the following error:number 234 for example. See image.

Sound_V1.ino:6:16: error: storage size of 'soundArray' isn't known
Error compiling.

This is not what I want. I want to get different numbers in the array of that moment. enter image description here

Hope someone can help me out. Thanks in advance.

How to store values inside an empty array and get the average integer?

Goodafternoon,

I want to read values (microphone MAX9814) of the Analog port A0 from Arduino and store the values that are incoming inside an array. After the values are stores in the array, I want to read out the values and store the average of the hole array in a value. Is this possible and how to achieve this? The size of the array I doesn't know.

I came up with the following:

const int micPin = A0;

 
int soundArray[];

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(micPin, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  int micValue = analogRead(micPin);
  Serial.println(micValue, DEC);
  //delay(400);
  
  for (int i = 0; i > 8; i++) {
    soundArray[i] = micValue;
    Serial.println(soundArray[i]);
  }

 
}

I receive the following error:

Sound_V1.ino:6:16: error: storage size of 'soundArray' isn't known
Error compiling.

Hope someone can help me out. Thanks in advance.

How to store values inside an empty array and get the average integer? [UPDATED QUESTION]

Goodafternoon,

I want to read values form a microphone (Adafruit MAX9814) connected to the Analog port A0 from Arduino and store the values that are incoming inside an array. 

After the values are stored in the array, I want to read out the values and store the number that is repeated most time in a variable. Is this possible and how to achieve this?

I came up with the following:

const int micPin = A0;
int soundArray[10];

void setup() {

  Serial.begin(9600);
  pinMode(micPin, INPUT); 

}

void loop() {

  int micValue = analogRead(micPin);
  Serial.println(micValue, DEC);
  //delay(400);
  
  for (int i = 0; i > 10; i++) {
    soundArray[i] = micValue;
    Serial.println(soundArray[i]);
  }
  delay(1000);
  Serial.println("End of for loop");

 
}

The problem now is that a value of the microphone will be repeated 10 times. So I will receive 10 times the number 234 for example. See image.

This is not what I want. I want to get different numbers in the array of that moment. enter image description here

Hope someone can help me out. Thanks in advance.

deleted 83 characters in body
Source Link
Caspert
  • 101
  • 1
  • 1
  • 3

Goodafternoon,

I want to read values (microphone MAX9814) of the Analog port A0 from Arduino and store the values that are incoming inside an array. After the values are stores in the array, I want to read out the values and store the average of the hole array in a value. Is this possible and how to achieve this? The size of the array I doesn't know.

I came up with the following:

const int micPin = A0;
int maxValue;
int minValue;


int soundArray[];

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(micPin, INPUT);
  maxValue = 0;
  minValue = 1023;
}

void loop() {
  // put your main code here, to run repeatedly:
  int micValue = analogRead(micPin);
  Serial.println(micValue, DEC);
  //delay(400);
  
  for (int i = 0; i > 8; i++) {
    soundArray[i] = micValue;
    Serial.println(soundArray[i]);
  }

 
}

I receive the following error:

Sound_V1.ino:6:16: error: storage size of 'soundArray' isn't known
Error compiling.

Hope someone can help me out. Thanks in advance.

Goodafternoon,

I want to read values (microphone MAX9814) of the Analog port A0 from Arduino and store the values that are incoming inside an array. After the values are stores in the array, I want to read out the values and store the average of the hole array in a value. Is this possible and how to achieve this? The size of the array I doesn't know.

I came up with the following:

const int micPin = A0;
int maxValue;
int minValue;


int soundArray[];

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(micPin, INPUT);
  maxValue = 0;
  minValue = 1023;
}

void loop() {
  // put your main code here, to run repeatedly:
  int micValue = analogRead(micPin);
  Serial.println(micValue, DEC);
  //delay(400);
  
  for (int i = 0; i > 8; i++) {
    soundArray[i] = micValue;
    Serial.println(soundArray[i]);
  }

 
}

I receive the following error:

Sound_V1.ino:6:16: error: storage size of 'soundArray' isn't known
Error compiling.

Hope someone can help me out. Thanks in advance.

Goodafternoon,

I want to read values (microphone MAX9814) of the Analog port A0 from Arduino and store the values that are incoming inside an array. After the values are stores in the array, I want to read out the values and store the average of the hole array in a value. Is this possible and how to achieve this? The size of the array I doesn't know.

I came up with the following:

const int micPin = A0;


int soundArray[];

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(micPin, INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  int micValue = analogRead(micPin);
  Serial.println(micValue, DEC);
  //delay(400);
  
  for (int i = 0; i > 8; i++) {
    soundArray[i] = micValue;
    Serial.println(soundArray[i]);
  }

 
}

I receive the following error:

Sound_V1.ino:6:16: error: storage size of 'soundArray' isn't known
Error compiling.

Hope someone can help me out. Thanks in advance.

Source Link
Caspert
  • 101
  • 1
  • 1
  • 3

How to store values inside an empty array and get the average integer?

Goodafternoon,

I want to read values (microphone MAX9814) of the Analog port A0 from Arduino and store the values that are incoming inside an array. After the values are stores in the array, I want to read out the values and store the average of the hole array in a value. Is this possible and how to achieve this? The size of the array I doesn't know.

I came up with the following:

const int micPin = A0;
int maxValue;
int minValue;


int soundArray[];

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(micPin, INPUT);
  maxValue = 0;
  minValue = 1023;
}

void loop() {
  // put your main code here, to run repeatedly:
  int micValue = analogRead(micPin);
  Serial.println(micValue, DEC);
  //delay(400);
  
  for (int i = 0; i > 8; i++) {
    soundArray[i] = micValue;
    Serial.println(soundArray[i]);
  }

 
}

I receive the following error:

Sound_V1.ino:6:16: error: storage size of 'soundArray' isn't known
Error compiling.

Hope someone can help me out. Thanks in advance.