title: Arduino: How to read SD card text file line by line
body: <p>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".</p>
  
  <p><strong>Code structure:</strong> <br>
  1. Open "data.txt" from SDcard <br>
  2. Read first line data <br>
  3. Input read data into int "TargetCur" <br>
  4. Arduino perform action <br>
  5. Once action above completed, read second line data from "data.txt" <br>
  6. Repeat step 3 to 5 above</p>
  
  <p>"<strong>data.txt</strong>" look like this: <br>
  Current <br>
  2.179<br>
  3.179<br>
  2.659<br>
  2.859<br></p>
  
  <pre><code>#include &lt;SPI.h&gt;
  #include &lt;SD.h&gt;
  
  File Data;
  
  // Declare the pins used:
  int TargetCur = 0;
  
  void setup() {    
      Serial.begin(9600);     // initialize serial communications at 9600 bps:
      TCCR1B = TCCR1B &amp; 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//
  }
  </code></pre>