“SD卡相关声明”的版本间的差异
502748957@qq.com(讨论 | 贡献) (创建页面,内容为“<pre style="color:green"> File myFile; Sd2Card card; SdVolume volume; SdFile root; </pre> *'''作用''':<br> File myFile; 声明文件操作类,用于文件写…”) |
502748957@qq.com(讨论 | 贡献) |
||
(未显示同一用户的6个中间版本) | |||
第1行: | 第1行: | ||
− | < | + | <p style="color: #666666;font-size:220%">'''SD各种类的实例化'''</p> |
+ | <br> | ||
File myFile; | File myFile; | ||
+ | |||
Sd2Card card; | Sd2Card card; | ||
+ | |||
SdVolume volume; | SdVolume volume; | ||
+ | |||
SdFile root; | SdFile root; | ||
− | </ | + | <p style="color: #E87E05;font-size:135%">'''作用'''</p> |
+ | **File myFile; | ||
+ | **声明文件操作类,用于文件写入或读取 | ||
− | * | + | **Sd2Card card; |
− | + | **声明SD卡类,用于读取SD卡信息等操作 | |
− | |||
− | + | **SdVolume volume; | |
− | + | **声明SD卡容量,用于读取SD卡容量及文件系统类型等操作 | |
− | + | **SdFile root; | |
− | + | **作用原理与File类声明相同,但是此处声明为SDFile类,用于文件操作 | |
− | + | **其具体构成与描述均在IDE安装路径下的“\libraries\_05_m_Module_SD\utility”中 | |
− | |||
− | + | <p style="color: #E87E05;font-size:135%">'''参数'''</p> | |
− | + | **类名可根据程序起为其他名字,此处为方便理解使用"card""volume""root""myFile"等 | |
+ | <p style="color: #E87E05;font-size:135%">'''示例'''</p> | ||
+ | **以上几种声明在Microduino IDE中的Module_SD库示例的CardInfo例程中均有使用<br> | ||
− | + | <source lang="cpp"> | |
− | |||
#include <SPI.h> | #include <SPI.h> | ||
#include <SD.h> | #include <SD.h> | ||
第116行: | 第121行: | ||
} | } | ||
− | </ | + | </source> |
<br> | <br> | ||
<p style="color: #E87E05;font-size:135%">其他</p> | <p style="color: #E87E05;font-size:135%">其他</p> | ||
− | *[[ | + | |
+ | * SD : | ||
+ | |||
+ | *[[SD.begin()|begin()]] | ||
+ | *[[SD.open|open()]] | ||
+ | |||
+ | * myFile : | ||
+ | |||
+ | *[[myFile.close()|close()]] | ||
+ | *[[myFile.available()|available()]] | ||
+ | *[[myFile.read()|read()]] | ||
<br> | <br> | ||
− | [[ | + | [[MCookie-SD Reference | 返回SD模块语法手册]] |
2018年5月16日 (三) 08:04的最新版本
SD各种类的实例化
File myFile;
Sd2Card card;
SdVolume volume;
SdFile root;
作用
- File myFile;
- 声明文件操作类,用于文件写入或读取
- Sd2Card card;
- 声明SD卡类,用于读取SD卡信息等操作
- SdVolume volume;
- 声明SD卡容量,用于读取SD卡容量及文件系统类型等操作
- SdFile root;
- 作用原理与File类声明相同,但是此处声明为SDFile类,用于文件操作
- 其具体构成与描述均在IDE安装路径下的“\libraries\_05_m_Module_SD\utility”中
参数
- 类名可根据程序起为其他名字,此处为方便理解使用"card""volume""root""myFile"等
示例
- 以上几种声明在Microduino IDE中的Module_SD库示例的CardInfo例程中均有使用
- 以上几种声明在Microduino IDE中的Module_SD库示例的CardInfo例程中均有使用
#include <SPI.h>
#include <SD.h>
// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;
// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
// Microduino SD module: pin 7
const int chipSelect = D7;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("\nInitializing SD card...");
// we'll use the initialization code from the utility libraries
// since we're just testing if the card is working!
if (!card.init(SPI_HALF_SPEED, chipSelect)) {
Serial.println("initialization failed. Things to check:");
Serial.println("* is a card inserted?");
Serial.println("* is your wiring correct?");
Serial.println("* did you change the chipSelect pin to match your shield or module?");
return;
} else {
Serial.println("Wiring is correct and a card is present.");
}
// print the type of card
Serial.print("\nCard type: ");
switch (card.type()) {
case SD_CARD_TYPE_SD1:
Serial.println("SD1");
break;
case SD_CARD_TYPE_SD2:
Serial.println("SD2");
break;
case SD_CARD_TYPE_SDHC:
Serial.println("SDHC");
break;
default:
Serial.println("Unknown");
}
// Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
if (!volume.init(card)) {
Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
return;
}
// print the type and size of the first FAT-type volume
uint32_t volumesize;
Serial.print("\nVolume type is FAT");
Serial.println(volume.fatType(), DEC);
Serial.println();
volumesize = volume.blocksPerCluster(); // clusters are collections of blocks
volumesize *= volume.clusterCount(); // we'll have a lot of clusters
volumesize *= 512; // SD card blocks are always 512 bytes
Serial.print("Volume size (bytes): ");
Serial.println(volumesize);
Serial.print("Volume size (Kbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.print("Volume size (Mbytes): ");
volumesize /= 1024;
Serial.println(volumesize);
Serial.println("\nFiles found on the card (name, date and size in bytes): ");
root.openRoot(volume);
// list all files in the card with date and size
root.ls(LS_R | LS_DATE | LS_SIZE);
}
void loop(void) {
}
其他
- SD :
- myFile :