1、硬件
2、代码
#include <SD.h>
#include <SPI.h> // needed for Arduino versions later than 0018const long _1000msTime = 1000; // 1000 milli seconds
unsigned long _1000msLastTime;File myFile;
int date;
int Lastdate;
String strDate;//读出的SD,每一行数据int pinSD = 4;
int pinW5500 = 53;/****************按行读取SD卡内的动作**************/
String ReadSdLine() {String myStr;digitalWrite(pinW5500,HIGH);while ((date = myFile.read()) >= 0) {if ((date == 10) && (13 == Lastdate)) {break;} else {myStr += char(date);}Lastdate = date;}return myStr;
}void setup()
{// 打开串口Serial.begin(9600);while (!Serial) {; //等待串口连接。仅本机USB口使用。}Serial.println("Serial is opened.");//SD卡初始化if (!SD.begin(pinSD)) {Serial.println("initialization failed!");return;}myFile = SD.open("VRtest.txt");
}void loop()
{TimeProc();}void TimeProc()
{String m_strd;//1000ms执行一次if ((millis() - _1000msLastTime) >= _1000msTime){_1000msLastTime = millis( ); //m_strd = ReadSdLine();if(m_strd!=""){//如果当前行不为空,表示动作文件没有到底strDate=m_strd; //SendToMBox(strDate);/将这行字符串给解析函数Serial.println(strDate);}else{/动作文件到底Serial.println("End Play");}}
}
3、测试
文本数据
将读取的数据发送到串口中