-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.cpp
More file actions
42 lines (34 loc) · 1.03 KB
/
log.cpp
File metadata and controls
42 lines (34 loc) · 1.03 KB
1
2
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
#include "SD.h"
#include "log.hpp"
void initializeLog(void) {
pinMode(csPin, OUTPUT);
// SD Card Initialization
if (!SD.begin())
Serial.println("SD card initialization failed");
}
void addLog(String message, String secondPartOfMessage="") {
File logFile=SD.open("log.txt", FILE_WRITE);
if (!logFile)
return Serial.println("could not open log.txt");
Serial.print("Logged: ");
if (secondPartOfMessage=="") {
logFile.println(message);
Serial.println(message);
} else {
logFile.print(message);
logFile.println(secondPartOfMessage);
Serial.print(message);
Serial.println(secondPartOfMessage);
}
logFile.close();
}
void printLog(void) {
File logFile=SD.open("log.txt", FILE_READ);
if (!logFile)
return Serial.println("could not open log.txt");
Serial.println("-----Printing log.txt-----");
while (logFile.available())
Serial.write(logFile.read());
Serial.println("---------------");
logFile.close();
}