|
大家好!! 第一次發文,請多指教
我的問題是將sd卡中的txt檔案內容
讀取至arduino陣列,方便做後續處理
我的b.txt內容為
0,38.711,38.712,38.713,38.714,38.715,38.726,38.727,38.728,38.729,38.7210,38.7111,38.7112,38.7213,38.7114,38.7115,38.7116,38.7117,38.7118,38.7119,38.7120,38.71
arduino code為
////////////
#include <SPI.h>
#include <SD.h>
File myFile;
char time[3],data[3],data1[3];
int time_array[402];
float data_array[402];
int t1=0,i=0,i1=0,ii=0,tt=0,ttt=0;
void setup()
{
Serial.begin(9600);
while (!Serial) {
;
}
Serial.print("Initializing SD card...");
if (!SD.begin(53)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
myFile = SD.open("b.txt");
while (myFile.available()) {
//Serial.println(t1);
//t1 += 1;
if ( t1 == 0 ) {
time[tt] = myFile.read();
//memset(time, 0, sizeof(time));
tt += 1;
if (myFile.read() == ',')
{
ttt = atoi(time);
t1 = 1;
}
}
//else {
if (t1 >= 1) {
if (i > 2 && t1 > 0) {
data1[i1] = myFile.read();
i1 += 1;
}
else {
data = myFile.read();
i += 1;
}
t1 += 1;
//}
}
if (t1 >= 6) {
int k = atoi(data);
int k1 = atoi(data1);
data_array[ii] = k + (k1/100.00);
time_array[ii] = ttt;
Serial.println(time_array[ii]);
Serial.println(data_array[ii]);
ii += 1;
i = 0;
i1 = 0;
t1 = 0;
tt = 0;
}
}
}
void loop()
{
// nothing happens after setup
}
////////////
下圖為輸出結果
問題就是
從10開始就沒print.....
找不出問題在哪....
希望大大們能幫我看看哪裡有問題!!
|
|