I have a CSV file where I have recorded data from an accelerometer. I'm trying to use this file as an input data source for my project.
the data is in the format:" 124, 235, 210, 190, 150 etc..."
I'm trying to create a For loop where it reads one value at a time so it can be written to a PWM.
is there a way to do this so that it reads the data at the same speed etc as it was recorded?
also, what syntax would be most appropriate in this situation?
halpo:
is there a way to do this so that it reads the data at the same speed etc as it was recorded?
Depends on what speed the data was written.
Hopefully it was written at a fixed rate that is reasonably slow, like less than 100 per second.
Use the "Blink without delay" example to see how you schedule thing to happen at regular time intervals.
In loop():
if you have a parsed value ready:
if it's time to send the next value:
analogWrite()
set the value to 0
mark the value as 'not ready'
else
if there is a character available in the file:
read the character
if the character is a comma:
mark the value as available
else
if the character is a digit:
multiply the value by 10 and add character - '0'
end of loop()
If you embed that CSV data in your sketch, for example in an array, you will need to code the sketch to process the array one element at a time at the correct rate. This is simple to do, but assumes you can fit all your data on the Arduino at once. That might not be feasible, depending how much data you have.
The other alternative is to hold the data on a PC, have an application on the PC which reads the file and writes it to the Arduino's serial port at the correct speed, and have a sketch that reads the serial port and processes each row as it receives it.