There are multiple issues with your program. The most obvious is that,
if you define a variable multiple times, you end up with mutliple
different variables that share the same name. For example:
void setup() {
int Vs[512] = {}; // this Vs is local to setup()
}
void loop() {
int i; // this i is local to loop()
for (int i = 0; // this other i is visible within the for loop only
i <= 511;
i++)
; // this is the body of the for loop
{
...
int Vs[i] = {c}; // this Vs is local to loop()
}
}
Another issue I pointed out in the snippet above is that a semicolon by
itself is an empty (i.e. do-nothing) statement. Thus you for loop is
empty.
There is no point in defining a constant such as analogPin = A0 if you
don't use it.
The value returned by micros() is not an int, it's an
unsigned log.
If you store a voltage in volts in an int, you get a very poor
resolution of one volt. You could store in a float, but that would
fill up the memory of your Arduino. I would rather store the raw
readings, and convert to volts only for printing.
Serial.println() takes time, and you are doing this during the timed
part of your code, which is probably unintended.
Here is a version of your program that may better reflect your
intentions. It takes 512 analog readings, stores them in an array, then
prints them and reports the time taken to do the readings. Then it waits
for one second and repeats the whole thing again.
const uint8_t analogPin = A0;
const int readings_count = 512;
int Vs[readings_count];
void setup() {
Serial.begin(9600);
}
void loop() {
// Take a run of analog readings.
unsigned long start_time = micros();
for (int i = 0; i < readings_count; i++) {
Vs[i] = analogRead(analogPin);
}
unsigned long stop_time = micros();
// Print the readings.
Serial.println("Voltage readings:");
for (int i = 0; i < readings_count; i++) {
Serial.println(5.0/1024 * Vs[i]);
}
Serial.print("Data recorded in ");
Serial.print(stop_time - start_time);
Serial.println(" µs");
Serial.println();
// Wait before the next run.
delay(1000);
}
If you really want to run only one iteration of the process, then you
can just replace delay(1000); by exit(0);. Alternatively, move the
body of loop() to the end of setup(), and keep an empty loop().
Vs[i] = analogRead(A0) * (5.000/1024.000);