code arduino
#include
#include
/* CSV File Reading */
File file;
int SC = 10;
char location;
bool readLine(File &f, char* line, size_t maxLen) {
for (size_t n = 0; n < maxLen; n++) {
int c = f.read();
if ( c < 0 && n == 0) return false; // EOF
if (c < 0 || c == '\n') {
line[n] = 0;
return true;
}
line[n] = c;
}
return false; // line too long
}
bool readVals(long* v1, String* v2) {
char line[200], *ptr, *str;
if (!readLine(file, line, sizeof(line))) {
return false; // EOF or too long
}
*v1 = strtol(line, &ptr, 10);
if (ptr == line) return false;
while (*ptr) {
if (*ptr++ == ',') break;
}
*v2 = strtol(ptr, &str, 10);
while (*ptr) {
if (*ptr++ == ',') break;
}
return str != ptr; // true if number found
}
/* Close CSV File Reading */
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
//SD Card Reader Setup
Serial.begin(9600);
if (!SD.begin(SC)) {
Serial.println("begin error");
return;
}
file = SD.open("USE.CSV", FILE_READ);
if (!file) {
Serial.println("open error");
return;
}
}
void loop() // run over and over
{
long x ;
String y;
while (readVals(&x, &y)) {
//First 4 Long datatype variables
Serial.println(x);
//Last 2 String type variables
Serial.println(y);
}
}
file sd card
101 | ,39:09:20:30 | |
102 | ,29:BF:ED:AF | |
103 | ,____________________ | |
104, | ____________________ | |
105, | ____________________ | |
107, | ____________________ | |
108, | ____________________ | |
109, | ____________________ | |
110, | ____________________ | |
111, | ____________________ | |
112, | ____________________ | |
113, | ____________________ | |
114, | ____________________ | |
115, | ____________________ |
แต่เวลา run ขึ้น
101
39
102
29
103
0
104
0
.
.
.
.
115
0
มีวิธีแก้ไหมครับ
ให้ตัดข้อความเฉพาะ \n ครับ จะได้ครบ 101,39:09:20:30