Serial.println(T[44100]);* } void loop() {} When I open the Serial gate, it returns the next: àüà So, What do I do to get the real value? Board used: Arduino Uno Rev. 3
This declares an empty array so that T[0] will cause a run time error and your sketch to either crash or behave unpredictably.
If you want to declare an empty array then it should be like this:
float T[] = {0, 0, 0, 0, 0, 0, 0, 0, 0};
The above declares an array of size 9. Where all the elements are initialized to the value of 0. Or you can initialize each element to what ever value you please.
The compiler sizes the array, when you don't, based on the number of initializers you supply (0).
A zero element array is useless.
float j = float(i);
In the old days, single letter names in the range i to m were always integers. There is NO reason to create a float from an int to assign an int to a float.
Serial.println(T[44100]);
You don't, and can't possibly, have that many elements in the array.
So, What do I do to get the real value?
Provide adequate space in the array so you are storing data in the array, not sh*tting all over memory you don't own.
Since you are only using one element of the array and that element doesn't rely on any other element you can calculate it directly. The answer is 1000.00
float sampleRate = 44100.00;
float sec = 1000.00;
float quantum() {
return (1.00 / sampleRate) * sec;
}
void setup() {
Serial.begin(9600);
unsigned i = 44100; // Note: Won't fit in a signed int.
float fraction = quantum() * i;
Serial.println(fraction);
}
void loop() {}