
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Set the pins used
#
define
cardSelect
4
File logfile;
// blink out an error code
void
error
(
uint8_t
errno) {
while
(
1
) {
uint8_t
i;
for
(i=
0
; i<errno; i++) {
digitalWrite
(
13
, HIGH);
delay
(
100
);
digitalWrite
(
13
, LOW);
delay
(
100
);
}
for
(i=errno; i<
10
; i++) {
delay
(
200
);
}
}
}
// This line is not needed if you have Adafruit SAMD board package 1.6.2+
// #define Serial SerialUSB
void
setup
() {
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
// also spit it out
Serial.
begin
(
115200
);
Serial.
println
(
"\r\nAnalog logger test"
);
pinMode
(
13
, OUTPUT);
// see if the card is present and can be initialized:
if
(!SD.
begin
(cardSelect)) {
Serial.
println
(
"Card init. failed!"
);
error
(
2
);
}
char
filename[
15
];
strcpy
(filename,
"/ANALOG00.TXT"
);
for
(
uint8_t
i =
0
; i <
100
; i++) {
filename[
7
] =
'0'
+ i/
10
;
filename[
8
] =
'0'
+ i%
10
;
// create if does not exist, do not open existing, write, sync after write
if
(! SD.
exists
(filename)) {
break
;
}
}
©Adafruit Industries
Page 37 of 39