I found an old post about this but it didn't really answer my question, so i will make a new one. I want to run a loop for a specific amount of time and take measurements in this loop at a specific rate. Here is the code i have so far, which does not seem to do what i want. It should run for 10 seconds doing a measurement each second. thanks
int sensePin = 0;
unsigned long starttime;
unsigned long endtime;
int i = 0;
int n;
const int sizeofv = 10;
int v[sizeofv];
void setup(){
pinMode(sensePin, INPUT);
Serial.begin(9600);
starttime = millis();
endtime = starttime;
while ((endtime - starttime) <= 10000)
{
i = i + 1;
v[i] = analogRead(sensePin);
delay(1000);
endtime = millis();
}
void loop(){
}
Ok yea i see i changed millis() and didnt change back... well i want to have a controlled amount of time for an observation. I had the code in matlab but i was not getting enough samples per second. so i figured i would try it here but im not good at the arduino environment.
You are putting data into the array indices v[1] to v[10] but, as array indices start from v[0], there's no v[10].
You haven't balanced your braces, so it won't compile.
i = i + 1; is the same as i++;
The endtime variable can be replaced with millis().
Much, but how would i use that to change the sampling frequency. I want to have it more like 1000 samples/sec and maybe run for 30-60 seconds. Sorry im such a noob.