Files

69 lines
1.0 KiB
Markdown
Raw Permalink Normal View History

2019-02-27 14:11:30 +08:00
# TF card
2019-02-27 11:57:45 +08:00
## begin()
2019-02-27 14:11:30 +08:00
**Syntax:**
2019-02-27 11:57:45 +08:00
2020-11-05 11:39:06 +08:00
`boolean begin(uint8_t cspin);`
2019-02-27 11:57:45 +08:00
2019-02-27 14:11:30 +08:00
**Description:**
2019-02-27 11:57:45 +08:00
2019-02-27 14:11:30 +08:00
This function initialize TF card.
| Argument | Description | Type |
| --- | --- | -- |
| cspin | chip select line (defaults SS line of SPI bus) | uint8_t |
2019-02-28 15:56:00 +08:00
**Example:**
2019-02-27 11:57:45 +08:00
2021-02-26 17:27:20 +08:00
```clike
2019-02-27 11:57:45 +08:00
#include <M5Stack.h>
2019-02-27 14:11:30 +08:00
void setup() {
SD.begin();
}
2019-02-27 11:57:45 +08:00
```
## open()
2019-02-27 14:11:30 +08:00
**Syntax:**
2019-02-27 11:57:45 +08:00
2020-11-05 11:39:06 +08:00
`File open(const char *filename, uint8_t mode = FILE_READ);`
2019-02-27 11:57:45 +08:00
2019-02-27 14:11:30 +08:00
**Description:**
2019-02-27 11:57:45 +08:00
2019-02-27 14:11:30 +08:00
This function open the file.
| Argument | Description | Type |
| --- | --- | -- |
| filepath | path to file | const char * |
| mode | read / write / rw (optional) | uint8_t |
2019-02-28 15:56:00 +08:00
**Example:**
2019-02-27 11:57:45 +08:00
2021-02-26 17:27:20 +08:00
```clike
2019-02-27 11:57:45 +08:00
/*
2019-02-27 14:11:30 +08:00
display contents of hello.txt in TF card to M5 screen.
2019-02-27 11:57:45 +08:00
*/
#include <M5Stack.h>
2019-02-27 14:11:30 +08:00
void setup() {
M5.begin();
if (!SD.begin()) {
M5.Lcd.println("Card failed, or not present");
while (1);
}
Serial.println("TF card initialized.");
File f = SD.open("/hello.txt", FILE_READ);
if (f) {
M5.Lcd.print(f.read());
f.close();
} else {
M5.Lcd.println("open error hello.txt");
}
2019-02-27 11:57:45 +08:00
}
2019-02-27 14:11:30 +08:00
void loop() {
2019-02-27 11:57:45 +08:00
}
```