Arduino 上手教程
类名:SD
功能说明:
初始化 TF 卡
函数原型:
begin(cspin);
参数 | 描述 |
---|---|
cspin | TF 的片选引脚 (默认是 SPI 的 SS 引脚),可选 |
案例程序:
#include <M5Stack.h> void setup() { SD.begin();}
功能说明:
以指定模式打开指定文件
函数原型:
File open(const char *filepath, uint8_t mode);
参数 | 描述 |
---|---|
filepath | 文件路径 |
mode | 打开模式 |
案例程序:
//请提前通过 PC 创建 hello.txt 并拷贝到 TF 卡根目录内#include <M5Stack.h> 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"); }} void loop() {}