我正在做一个从 SD 卡读取“data.txt”中的“当前”的项目。目标是逐行阅读并输入到我的int“TargetCur”。
代码结构:
1. 从 SDcard 打开“data.txt”
2. 读取第一行数据
3. 将读取的数据输入 int "TargetCur"
4. Arduino 执行动作
5. 上述动作完成后,从“data.txt”读取第二行数据"
6. 重复上述步骤 3 至 5
“ data.txt ”看起来像这样:
当前
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//
}