I'm working on a project to read "current" in "data.txt" from SDcard. Goal is to read it line by line and input to my int "TargetCur".
Code structure:
1. Open "data.txt" from SDcard
2. Read first line data
3. Input read data into int "TargetCur"
4. Arduino perform action
5. Once action above completed, read second line data from "data.txt"
6. Repeat step 3 to 5 above
"data.txt" look like this:
Current
2.179
3.179
2.659
2.859
#include <SPI.h>
#include <SD.h>
File Data;
// Declare the pins used:
int TargetCur = 0;
void setup() {
Serial.begin(9600); // initialize serial communications at 9600 bps:
TCCR1B = TCCR1B & B11111000 | B00000001;
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
myFile = SD.open ("data.txt", FILE_WRITE);
}
void loop() {
TargetCur = Serial.write(myFile.read());
//perform action//
}