首页 > 评测 > 8位机也玩音频-Arduino+SD+DAC+运放打造的播放器
8位机也玩音频-Arduino+SD+DAC+运放打造的播放器
- [导读]
- 比如本文要介绍的Adafruit Wave Shield,就能是专门为Arduino设计的音频模块.确切的说是为AVR这一类的8位机而设计的音频模块.下文将从硬件到软件详细介绍一下子此模块的设计细节与使用方法.
FatReader root; // This holds the information for the volumes root directory
WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time
uint8_t dirLevel; // indent level for file/dir names (for prettyprinting)
dir_t dirBuf; // buffer for directory reads
/*
* Define macro to put error messages in flash memory
*/
#define error(msg) error_P(PSTR(msg))
// Function definitions (we define them here, but the code is below)
void play(FatReader &dir);
//Arduino程序的初始化函数,主要是加载文件系统
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps for debugging
putstring_nl("\nWave test!"); // say we woke up!
putstring("Free RAM: "); // This can help with debugging, running out of RAM is bad
Serial.println(FreeRam());
// if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
if (!card.init()) { //play with 8 MHz spi (default faster!)
error("Card init. failed!"); // Something went wrong, lets print out why
}
// enable optimize read - some cards may timeout. Disable if you're having problems
card.partialBlockRead(true);
// Now we will look for a FAT partition!
uint8_t part;
for (part = 0; part < 5; part++) { // we have up to 5 slots to look in
if (vol.init(card, part))
break; // we found one, lets bail
}
if (part == 5) { // if we ended up not finding one :(
error("No valid FAT partition!"); // Something went wrong, lets print out why
}
// Lets tell the user about what we found
putstring("Using partition ");
Serial.print(part, DEC);
putstring(", type is FAT");
Serial.println(vol.fatType(), DEC); // FAT16 or FAT32?
// Try to open the root directory
if (!root.openRoot(vol)) {
error("Can't open root dir!"); // Something went wrong,
}
// Whew! We got past the tough parts.
putstring_nl("Files found (* = fragmented):");
// Print out all of the files in all the directories.
root.ls(LS_R | LS_FLAG_FRAGMENTED);
}
//主循环就是播放,播放是通过中断来进行的,所以也可以同时做其他操作
void loop() {
root.rewind();
play(root);
}
//一些出错报告函数
/*
* print error message and halt
*/
void error_P(const char *str) {
PgmPrint("Error: ");
SerialPrint_P(str);
sdErrorCheck();
while(1);
}
/*
* print error message and halt if SD I/O error, great for debugging!
*/
void sdErrorCheck(void) {
if (!card.errorCode()) return;
PgmPrint("\r\nSD I/O error: ");
Serial.print(card.errorCode(), HEX);
- 本文系21ic原创,未经许可禁止转载!
网友评论
- 联系人:巧克力娃娃
- 邮箱:board@21ic.com
- 我要投稿
-
欢迎入驻,开放投稿
-
RAK831 Lite:基于树莓派3的LoRa网关... 2022-06-17
-
Imagination推出PowerVR AX2185和AX2145神经... 2022-06-17
-
ODROID-GO是一款兼容Arduino的基于ESP32的便... 2022-06-17
- PID温度控制器
预算:¥700003天前
- 摄像头的可视画面需要一直超上(linux系统,ARM)
预算:¥1000018小时前
- DICOM协议搭建(ARM架构,linux系统)
预算:¥1000017小时前
- 需MIPI摄像头隔离电路,实现3-4米能长距离
预算:¥1000017小时前
- 膨宫仪的控制板,控制流量和检测压力
预算:¥1000016分钟前
- 无创自动测量血压计 NIBP模块
预算:¥100007小时前