“音乐盒/zh”的版本间的差异
502748957@qq.com(讨论 | 贡献) (→组装) |
502748957@qq.com(讨论 | 贡献) (→程序说明) |
||
第121行: | 第121行: | ||
在uiSetup中更改阈值设定 | 在uiSetup中更改阈值设定 | ||
==程序说明== | ==程序说明== | ||
+ | Simple_player.ino | ||
<source lang="cpp"> | <source lang="cpp"> | ||
+ | #define music_num_MAX 8 //歌曲最大数,可改 | ||
+ | |||
+ | #include <SoftwareSerial.h> | ||
+ | //用户自定义部分------------------------ | ||
+ | |||
+ | #include <Wire.h> | ||
+ | |||
+ | //EEPROM--------------------- | ||
+ | #include <EEPROM.h> | ||
+ | #define EEPROM_write(address, p) {int i = 0; byte *pp = (byte*)&(p);for(; i < sizeof(p); i++) EEPROM.write(address+i, pp[i]);} | ||
+ | #define EEPROM_read(address, p) {int i = 0; byte *pp = (byte*)&(p);for(; i < sizeof(p); i++) pp[i]=EEPROM.read(address+i);} | ||
+ | |||
+ | struct config_type | ||
+ | { | ||
+ | int EEPROM_music_num; | ||
+ | int EEPROM_music_vol; | ||
+ | }; | ||
+ | |||
+ | //用户自定义部分------------------------ | ||
+ | #include "audio.h" | ||
+ | |||
+ | #include "U8glib.h" | ||
+ | //-------字体设置,大、中、小 | ||
+ | #define setFont_L u8g.setFont(u8g_font_7x13) | ||
+ | #define setFont_M u8g.setFont(u8g_font_fixed_v0r) | ||
+ | #define setFont_S u8g.setFont(u8g_font_fixed_v0r) | ||
+ | /* | ||
+ | font: | ||
+ | u8g_font_7x13 | ||
+ | u8g_font_fixed_v0r | ||
+ | u8g_font_chikitar | ||
+ | u8g_font_osb21 | ||
+ | u8g_font_courB14r | ||
+ | u8g_font_courB24n | ||
+ | u8g_font_9x18Br | ||
+ | */ | ||
+ | |||
+ | //屏幕类型-------- | ||
+ | U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); | ||
+ | |||
+ | #define init_draw 500 //主界面刷新时间 | ||
+ | unsigned long timer_draw; | ||
+ | |||
+ | int MENU_FONT = 1; //初始化字体大小 0:小,1:中,2:大 | ||
+ | |||
+ | boolean music_status = false; //歌曲播放状态 | ||
+ | int music_num = 1; //歌曲序号 | ||
+ | int music_vol=20; //音量0~30 | ||
+ | |||
+ | |||
+ | boolean key,key_cache; | ||
+ | |||
+ | unsigned long music_vol_time_cache=0; | ||
+ | unsigned long music_vol_time=0; | ||
+ | boolean music_vol_sta=false; | ||
+ | |||
+ | int uiStep() | ||
+ | { | ||
+ | if(analogRead(A6)<50) | ||
+ | { | ||
+ | delay(50); | ||
+ | if(analogRead(A6)<50) | ||
+ | return 1; | ||
+ | } | ||
+ | // if(analogRead(A6)>300 && analogRead(A6)<400) | ||
+ | // { | ||
+ | // delay(50); | ||
+ | // if(analogRead(A6)>300 && analogRead(A6)<400) | ||
+ | // return 2; | ||
+ | // } | ||
+ | if(analogRead(A6)>140 && analogRead(A6)<400) | ||
+ | { | ||
+ | delay(50); | ||
+ | if(analogRead(A6)>140 && analogRead(A6)<400) | ||
+ | return 2; | ||
+ | } | ||
+ | // if(analogRead(A6)>200 && analogRead(A6)<250) | ||
+ | // { | ||
+ | // delay(50); | ||
+ | // if(analogRead(A6)>200 && analogRead(A6)<250) | ||
+ | // return 3; | ||
+ | // } | ||
+ | if(analogRead(A6)>70 && analogRead(A6)<100) | ||
+ | { | ||
+ | delay(50); | ||
+ | if(analogRead(A6)>70 && analogRead(A6)<100) | ||
+ | return 3; | ||
+ | } | ||
+ | |||
+ | return 0; | ||
+ | } | ||
+ | |||
+ | void setup() | ||
+ | { | ||
+ | Serial.begin(9600); | ||
+ | |||
+ | //EEPROM--------------------- | ||
+ | eeprom_READ(); | ||
+ | |||
+ | //初始化mp3模块 | ||
+ | audio_init(DEVICE_TF,MODE_loopOne,music_vol); //初始化mp3模块 | ||
+ | |||
+ | // u8g.setRot180(); // rotate screen, if required | ||
+ | } | ||
+ | |||
+ | void loop() | ||
+ | { | ||
+ | Serial.println(analogRead(A6)); | ||
+ | int vol=uiStep(); //检测输入动作 | ||
+ | // Serial.print("vol:"); | ||
+ | // Serial.println(vol); | ||
+ | |||
+ | if(vol==1) key=true; | ||
+ | else key=false; | ||
+ | |||
+ | if(!key && key_cache) //按下松开后 | ||
+ | { | ||
+ | key_cache=key; //缓存作判断用 | ||
+ | music_status=!music_status; //播放或暂停 | ||
+ | if(music_status == true) //播放 | ||
+ | { | ||
+ | Serial.println("play"); | ||
+ | // audio_choose(1); | ||
+ | audio_play(); | ||
+ | } | ||
+ | else //暂停 | ||
+ | { | ||
+ | Serial.println("pause"); | ||
+ | audio_pause(); | ||
+ | } | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | key_cache=key; //缓存作判断用 | ||
+ | } | ||
+ | |||
+ | if(vol==0) | ||
+ | { | ||
+ | // Serial.println("no"); | ||
+ | music_vol_time_cache=millis(); | ||
+ | music_vol_time=music_vol_time_cache; | ||
+ | music_vol_sta=false; | ||
+ | } | ||
+ | else if(vol==2) | ||
+ | { | ||
+ | music_vol_time=millis()-music_vol_time_cache; | ||
+ | // if(music_vol_time>200) | ||
+ | delay(500); | ||
+ | if(uiStep()==0 && !music_vol_sta) | ||
+ | { | ||
+ | Serial.println("next"); | ||
+ | |||
+ | music_num++; //歌曲序号加 | ||
+ | if(music_num>music_num_MAX) //限制歌曲序号范围 | ||
+ | { | ||
+ | music_num=1; | ||
+ | } | ||
+ | audio_choose(music_num); | ||
+ | audio_play(); | ||
+ | // delay(500); | ||
+ | music_status=true; | ||
+ | eeprom_WRITE(); | ||
+ | |||
+ | } | ||
+ | else if(music_vol_time>1500) | ||
+ | { | ||
+ | music_vol_sta=true; | ||
+ | music_vol++; | ||
+ | if(music_vol>30) music_vol=30; | ||
+ | audio_vol(music_vol); | ||
+ | Serial.println("++"); | ||
+ | delay(100); | ||
+ | eeprom_WRITE(); | ||
+ | } | ||
+ | } | ||
+ | else if(vol==3) | ||
+ | { | ||
+ | music_vol_time=millis()-music_vol_time_cache; | ||
+ | // if(music_vol_time>200) | ||
+ | delay(500); | ||
+ | if(uiStep()==0 && !music_vol_sta) | ||
+ | { | ||
+ | Serial.println("perv"); | ||
+ | |||
+ | music_num--; //歌曲序号加 | ||
+ | if(music_num<1) //限制歌曲序号范围 | ||
+ | { | ||
+ | music_num=music_num_MAX; | ||
+ | } | ||
+ | audio_choose(music_num); | ||
+ | audio_play(); | ||
+ | // delay(500); | ||
+ | music_status=true; | ||
+ | eeprom_WRITE(); | ||
+ | } | ||
+ | else if(music_vol_time>1500) | ||
+ | { | ||
+ | music_vol_sta=true; | ||
+ | music_vol--; | ||
+ | if(music_vol<1) music_vol=1; | ||
+ | audio_vol(music_vol); | ||
+ | Serial.println("--"); | ||
+ | delay(100); | ||
+ | eeprom_WRITE(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if(millis()-timer_draw>init_draw) | ||
+ | { | ||
+ | u8g.firstPage(); | ||
+ | do { | ||
+ | draw(); | ||
+ | } | ||
+ | while( u8g.nextPage() ); | ||
+ | timer_draw=millis(); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | void eeprom_WRITE() | ||
+ | { | ||
+ | config_type config; // 定义结构变量config,并定义config的内容 | ||
+ | config.EEPROM_music_num=music_num; | ||
+ | config.EEPROM_music_vol=music_vol; | ||
+ | |||
+ | EEPROM_write(0, config); // 变量config存储到EEPROM,地址0写入 | ||
+ | } | ||
+ | |||
+ | void eeprom_READ() | ||
+ | { | ||
+ | config_type config_readback; | ||
+ | EEPROM_read(0, config_readback); | ||
+ | music_num=config_readback.EEPROM_music_num; | ||
+ | music_vol=config_readback.EEPROM_music_vol; | ||
+ | } | ||
+ | |||
+ | unsigned int freeRam () { | ||
+ | extern unsigned int __heap_start, *__brkval; | ||
+ | unsigned int v; | ||
+ | return (unsigned int) &v - (__brkval == 0 ? (unsigned int) &__heap_start : (unsigned int) __brkval); | ||
+ | } | ||
+ | |||
+ | //主界面,可自由定义 | ||
+ | void draw() | ||
+ | { | ||
+ | setFont_L; | ||
+ | |||
+ | u8g.setPrintPos(4, 16); | ||
+ | u8g.print("Music_sta:"); | ||
+ | u8g.print(music_status ? "play" : "pause"); | ||
+ | |||
+ | u8g.setPrintPos(4, 16*2); | ||
+ | u8g.print("Music_vol:"); | ||
+ | u8g.print(music_vol); | ||
+ | u8g.print("/30"); | ||
+ | u8g.setPrintPos(4, 16*3); | ||
+ | u8g.print("Music_num:"); | ||
+ | u8g.print(music_num); | ||
+ | u8g.print("/"); | ||
+ | u8g.print(music_num_MAX); | ||
+ | u8g.setPrintPos(4, 16*4); | ||
+ | u8g.print("....Microduino...."); | ||
+ | } | ||
</source> | </source> | ||
+ | Audio.h | ||
+ | <source lang="cpp"> | ||
+ | #include "arduino.h" | ||
+ | #include <SoftwareSerial.h> | ||
+ | |||
+ | SoftwareSerial mySerial(2, 3); // RX, TX | ||
+ | |||
+ | #define AUDIO_PORT mySerial //Core+ | ||
+ | //#define AUDIO_PORT mySerial //Core | ||
+ | |||
+ | byte sn_reset[4]= | ||
+ | { | ||
+ | 0x7E,0x02,0x0C,0xEF | ||
+ | }; | ||
+ | |||
+ | byte sn_choose[6]= | ||
+ | { | ||
+ | 0x7E,0x04,0x03,0x00,0x01,0xEF | ||
+ | }; | ||
+ | |||
+ | byte sn_vol[5]= | ||
+ | { | ||
+ | 0x7E,0x03,0x06,0x18,0xEF | ||
+ | }; | ||
+ | |||
+ | byte sn_device[5]= | ||
+ | { | ||
+ | 0x7E,0x03,0x09,0x01,0xEF | ||
+ | }; | ||
+ | |||
+ | byte sn_pause[4]= | ||
+ | { | ||
+ | 0x7E,0x02,0x0E,0xEF | ||
+ | }; | ||
+ | |||
+ | byte sn_play[4]= | ||
+ | { | ||
+ | 0x7E,0x02,0x0D,0xEF | ||
+ | }; | ||
+ | |||
+ | byte sn_mode[5]= | ||
+ | { | ||
+ | 0x7E,0x03,0x11,0x00,0xEF | ||
+ | }; | ||
+ | |||
+ | byte sn_down[4]= | ||
+ | { | ||
+ | 0x7E,0x02,0x01,0xEF | ||
+ | }; | ||
+ | |||
+ | byte sn_up[4]= | ||
+ | { | ||
+ | 0x7E,0x02,0x02,0xEF | ||
+ | }; | ||
+ | |||
+ | byte sn_eq[5]= | ||
+ | { | ||
+ | 0x7E,0x03,0x07,0x01,0xEF | ||
+ | }; | ||
+ | |||
+ | //----------------------------- | ||
+ | void audio_pause() | ||
+ | { | ||
+ | AUDIO_PORT.write(sn_pause,4); | ||
+ | delay(50); | ||
+ | } | ||
+ | |||
+ | void audio_play() | ||
+ | { | ||
+ | AUDIO_PORT.write(sn_play,4); | ||
+ | delay(50); | ||
+ | } | ||
+ | |||
+ | //play eq (Normal/Pop/Rock/Jazz/Classic/Base) 0-5 | ||
+ | void audio_eq(byte _audio_eq) | ||
+ | { | ||
+ | sn_mode[3]=_audio_eq; | ||
+ | AUDIO_PORT.write(sn_eq,5); | ||
+ | delay(100); | ||
+ | } | ||
+ | |||
+ | #define MODE_loopAll 0 | ||
+ | #define MODE_loopOne 1 | ||
+ | #define MODE_One_STOP 2 | ||
+ | #define MODE_One_END 4 | ||
+ | //play mode (ALL/FOL/ONE/RAM/ONE_STOP) 0-4 | ||
+ | void audio_mode(byte _audio_mode) | ||
+ | { | ||
+ | sn_mode[3]=_audio_mode; | ||
+ | AUDIO_PORT.write(sn_mode,5); | ||
+ | delay(100); | ||
+ | } | ||
+ | |||
+ | #define DEVICE_Flash 5 | ||
+ | #define DEVICE_TF 1 | ||
+ | //device select (U/TF/AUX/SLEEP/FLASH) 0-4 | ||
+ | void audio_device(byte _audio_device) | ||
+ | { | ||
+ | sn_device[3]=_audio_device; | ||
+ | AUDIO_PORT.write(sn_device,5); | ||
+ | delay(1500); | ||
+ | } | ||
+ | |||
+ | void audio_down() | ||
+ | { | ||
+ | AUDIO_PORT.write(sn_down,4); | ||
+ | delay(500); | ||
+ | } | ||
+ | |||
+ | void audio_up() | ||
+ | { | ||
+ | AUDIO_PORT.write(sn_up,4); | ||
+ | delay(500); | ||
+ | } | ||
+ | |||
+ | void audio_vol(byte _audio_vol) | ||
+ | { | ||
+ | sn_vol[3]=_audio_vol; | ||
+ | AUDIO_PORT.write(sn_vol,5); | ||
+ | delay(50); | ||
+ | } | ||
+ | |||
+ | void audio_choose(byte _audio_choose) | ||
+ | { | ||
+ | sn_choose[4]=_audio_choose; | ||
+ | AUDIO_PORT.write(sn_choose,6); | ||
+ | delay(100); | ||
+ | } | ||
+ | |||
+ | void audio_reset() | ||
+ | { | ||
+ | AUDIO_PORT.write(sn_reset,4); | ||
+ | delay(500); | ||
+ | } | ||
+ | |||
+ | void audio_init(int _audio_init_device,int _audio_init_mode,int _audio_init_vol) | ||
+ | { | ||
+ | AUDIO_PORT.begin(9600); | ||
+ | delay(500); | ||
+ | audio_reset(); | ||
+ | audio_device(_audio_init_device); | ||
+ | audio_mode(_audio_init_mode); | ||
+ | audio_vol(_audio_init_vol); | ||
+ | //audio_choose(1); | ||
+ | //audio_pause(); | ||
+ | } | ||
+ | </source> | ||
+ | |||
==视频== | ==视频== |
2015年11月24日 (二) 02:34的版本
概述
插卡音箱一般是指目前市场上支持或者能够读取SD、TF等等这些内存处理器的音箱,与传统的电脑音箱,手机音箱相比,插卡音箱独有的解码功能,使得它更为消费者所青睐,正因如此,它才被成为音响帝国中的解码大王。插卡音箱以实用,方便,最大限度的满足音箱消费者的需求为设计理念,产品设计简洁,使用高品质喇叭,音质震撼,还原度高,即使在最大音量下破音依然不明显,是追求完美音质的明智选择,还原效果明显,失真度低,被誉为音响王国中的音乐天使。精简按键设计、屏幕显示,无须复杂操作,轻松使用。 材料清单
实验原理Microduino-Audio板可解码并存储音乐文件,Microduino-Audio&shield 与喇叭连接实现音乐拨轮及大容量存储,Microduino-Cube-S1与Microduino-OLED连接可以直观的文字提示方式在OLED中显示音量及曲目。再将Microduino-USBTTL,Microduino-Core+与其他模块无序拼接即可实现插卡音箱功能。音箱外形采用木质外壳也可DIY自己的专属外壳。
文档调试过程将Microduino-Core+/zh、Microduino-USBTTL/zh堆叠在一起.用数据线将写好的程序通过Microduino-USBTTL/zh上传到Microduino-Core+/zh上。 注意:最好不要将所有模块堆叠在一起之后再上传程序 打开Arduino IDE编程软件,点击 【文件】->【打开】,打开插卡音箱文件夹后选择Microduino_Audio_ble\ Microduino_Audio_ble.ino 点击"√",编译程序。 点击【工具】,选择正确的板+处理器+端口。 点击"→",进行上传。
连接Audio模块到电脑。若成功识别,则“我的电脑”中会出现CD驱动,打开CD驱动。 注意:若未成功识别请检查数据线与模块之间是否插牢。如检查插牢还不能识别就换个电脑USB接口试试。 连接成功能显示出一个名为Microduino-Audio的CD驱动器,然后执行以下步骤: 打开驱动后选择MusicDownload.exe 打开后选择“音频加载” 点击“浏览”后选择所有歌曲,点击“打开”(歌曲在Case1-4.mp3中)。 注意:Flash中音乐文件不能超过4M,因此显屏中只有Music Num:1-4号有歌曲,5-9号歌曲还是上一首歌。如果想要增加歌曲,则使用第一种方法即音乐存入MicroSD卡 打开后点击返回“更新下载”,点击“更新”,点击更新,更新时间较长,请耐心等待 当现显示“校验成功”后,拷贝音乐就成功了。 注意:校验成功后直接关闭窗口,不要再点击更新,否则又要重新更新
将Audio&Shield模块通过USB数据线连接到电脑,此时会识别出一个CD驱动一个可移动磁盘。双击可移动磁盘 点击鼠标右键新建文件夹,命名为01(如需要多个可继续命名为02,03以此类推) 之后将音乐存储进文件夹01中即可 组装如图,请点击查看大图并对应步骤进行拼装
至此音乐盒拼装完成 注意事项1. 如果发生:只能增加音量不能减少音量,只能增加歌曲号不能减少歌曲号,或反之。 原因:uiStep()中阈值设定不合理。
在uiSetup中更改阈值设定 程序说明Simple_player.ino #define music_num_MAX 8 //歌曲最大数,可改
#include <SoftwareSerial.h>
//用户自定义部分------------------------
#include <Wire.h>
//EEPROM---------------------
#include <EEPROM.h>
#define EEPROM_write(address, p) {int i = 0; byte *pp = (byte*)&(p);for(; i < sizeof(p); i++) EEPROM.write(address+i, pp[i]);}
#define EEPROM_read(address, p) {int i = 0; byte *pp = (byte*)&(p);for(; i < sizeof(p); i++) pp[i]=EEPROM.read(address+i);}
struct config_type
{
int EEPROM_music_num;
int EEPROM_music_vol;
};
//用户自定义部分------------------------
#include "audio.h"
#include "U8glib.h"
//-------字体设置,大、中、小
#define setFont_L u8g.setFont(u8g_font_7x13)
#define setFont_M u8g.setFont(u8g_font_fixed_v0r)
#define setFont_S u8g.setFont(u8g_font_fixed_v0r)
/*
font:
u8g_font_7x13
u8g_font_fixed_v0r
u8g_font_chikitar
u8g_font_osb21
u8g_font_courB14r
u8g_font_courB24n
u8g_font_9x18Br
*/
//屏幕类型--------
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);
#define init_draw 500 //主界面刷新时间
unsigned long timer_draw;
int MENU_FONT = 1; //初始化字体大小 0:小,1:中,2:大
boolean music_status = false; //歌曲播放状态
int music_num = 1; //歌曲序号
int music_vol=20; //音量0~30
boolean key,key_cache;
unsigned long music_vol_time_cache=0;
unsigned long music_vol_time=0;
boolean music_vol_sta=false;
int uiStep()
{
if(analogRead(A6)<50)
{
delay(50);
if(analogRead(A6)<50)
return 1;
}
// if(analogRead(A6)>300 && analogRead(A6)<400)
// {
// delay(50);
// if(analogRead(A6)>300 && analogRead(A6)<400)
// return 2;
// }
if(analogRead(A6)>140 && analogRead(A6)<400)
{
delay(50);
if(analogRead(A6)>140 && analogRead(A6)<400)
return 2;
}
// if(analogRead(A6)>200 && analogRead(A6)<250)
// {
// delay(50);
// if(analogRead(A6)>200 && analogRead(A6)<250)
// return 3;
// }
if(analogRead(A6)>70 && analogRead(A6)<100)
{
delay(50);
if(analogRead(A6)>70 && analogRead(A6)<100)
return 3;
}
return 0;
}
void setup()
{
Serial.begin(9600);
//EEPROM---------------------
eeprom_READ();
//初始化mp3模块
audio_init(DEVICE_TF,MODE_loopOne,music_vol); //初始化mp3模块
// u8g.setRot180(); // rotate screen, if required
}
void loop()
{
Serial.println(analogRead(A6));
int vol=uiStep(); //检测输入动作
// Serial.print("vol:");
// Serial.println(vol);
if(vol==1) key=true;
else key=false;
if(!key && key_cache) //按下松开后
{
key_cache=key; //缓存作判断用
music_status=!music_status; //播放或暂停
if(music_status == true) //播放
{
Serial.println("play");
// audio_choose(1);
audio_play();
}
else //暂停
{
Serial.println("pause");
audio_pause();
}
}
else
{
key_cache=key; //缓存作判断用
}
if(vol==0)
{
// Serial.println("no");
music_vol_time_cache=millis();
music_vol_time=music_vol_time_cache;
music_vol_sta=false;
}
else if(vol==2)
{
music_vol_time=millis()-music_vol_time_cache;
// if(music_vol_time>200)
delay(500);
if(uiStep()==0 && !music_vol_sta)
{
Serial.println("next");
music_num++; //歌曲序号加
if(music_num>music_num_MAX) //限制歌曲序号范围
{
music_num=1;
}
audio_choose(music_num);
audio_play();
// delay(500);
music_status=true;
eeprom_WRITE();
}
else if(music_vol_time>1500)
{
music_vol_sta=true;
music_vol++;
if(music_vol>30) music_vol=30;
audio_vol(music_vol);
Serial.println("++");
delay(100);
eeprom_WRITE();
}
}
else if(vol==3)
{
music_vol_time=millis()-music_vol_time_cache;
// if(music_vol_time>200)
delay(500);
if(uiStep()==0 && !music_vol_sta)
{
Serial.println("perv");
music_num--; //歌曲序号加
if(music_num<1) //限制歌曲序号范围
{
music_num=music_num_MAX;
}
audio_choose(music_num);
audio_play();
// delay(500);
music_status=true;
eeprom_WRITE();
}
else if(music_vol_time>1500)
{
music_vol_sta=true;
music_vol--;
if(music_vol<1) music_vol=1;
audio_vol(music_vol);
Serial.println("--");
delay(100);
eeprom_WRITE();
}
}
if(millis()-timer_draw>init_draw)
{
u8g.firstPage();
do {
draw();
}
while( u8g.nextPage() );
timer_draw=millis();
}
}
void eeprom_WRITE()
{
config_type config; // 定义结构变量config,并定义config的内容
config.EEPROM_music_num=music_num;
config.EEPROM_music_vol=music_vol;
EEPROM_write(0, config); // 变量config存储到EEPROM,地址0写入
}
void eeprom_READ()
{
config_type config_readback;
EEPROM_read(0, config_readback);
music_num=config_readback.EEPROM_music_num;
music_vol=config_readback.EEPROM_music_vol;
}
unsigned int freeRam () {
extern unsigned int __heap_start, *__brkval;
unsigned int v;
return (unsigned int) &v - (__brkval == 0 ? (unsigned int) &__heap_start : (unsigned int) __brkval);
}
//主界面,可自由定义
void draw()
{
setFont_L;
u8g.setPrintPos(4, 16);
u8g.print("Music_sta:");
u8g.print(music_status ? "play" : "pause");
u8g.setPrintPos(4, 16*2);
u8g.print("Music_vol:");
u8g.print(music_vol);
u8g.print("/30");
u8g.setPrintPos(4, 16*3);
u8g.print("Music_num:");
u8g.print(music_num);
u8g.print("/");
u8g.print(music_num_MAX);
u8g.setPrintPos(4, 16*4);
u8g.print("....Microduino....");
}
Audio.h #include "arduino.h"
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX
#define AUDIO_PORT mySerial //Core+
//#define AUDIO_PORT mySerial //Core
byte sn_reset[4]=
{
0x7E,0x02,0x0C,0xEF
};
byte sn_choose[6]=
{
0x7E,0x04,0x03,0x00,0x01,0xEF
};
byte sn_vol[5]=
{
0x7E,0x03,0x06,0x18,0xEF
};
byte sn_device[5]=
{
0x7E,0x03,0x09,0x01,0xEF
};
byte sn_pause[4]=
{
0x7E,0x02,0x0E,0xEF
};
byte sn_play[4]=
{
0x7E,0x02,0x0D,0xEF
};
byte sn_mode[5]=
{
0x7E,0x03,0x11,0x00,0xEF
};
byte sn_down[4]=
{
0x7E,0x02,0x01,0xEF
};
byte sn_up[4]=
{
0x7E,0x02,0x02,0xEF
};
byte sn_eq[5]=
{
0x7E,0x03,0x07,0x01,0xEF
};
//-----------------------------
void audio_pause()
{
AUDIO_PORT.write(sn_pause,4);
delay(50);
}
void audio_play()
{
AUDIO_PORT.write(sn_play,4);
delay(50);
}
//play eq (Normal/Pop/Rock/Jazz/Classic/Base) 0-5
void audio_eq(byte _audio_eq)
{
sn_mode[3]=_audio_eq;
AUDIO_PORT.write(sn_eq,5);
delay(100);
}
#define MODE_loopAll 0
#define MODE_loopOne 1
#define MODE_One_STOP 2
#define MODE_One_END 4
//play mode (ALL/FOL/ONE/RAM/ONE_STOP) 0-4
void audio_mode(byte _audio_mode)
{
sn_mode[3]=_audio_mode;
AUDIO_PORT.write(sn_mode,5);
delay(100);
}
#define DEVICE_Flash 5
#define DEVICE_TF 1
//device select (U/TF/AUX/SLEEP/FLASH) 0-4
void audio_device(byte _audio_device)
{
sn_device[3]=_audio_device;
AUDIO_PORT.write(sn_device,5);
delay(1500);
}
void audio_down()
{
AUDIO_PORT.write(sn_down,4);
delay(500);
}
void audio_up()
{
AUDIO_PORT.write(sn_up,4);
delay(500);
}
void audio_vol(byte _audio_vol)
{
sn_vol[3]=_audio_vol;
AUDIO_PORT.write(sn_vol,5);
delay(50);
}
void audio_choose(byte _audio_choose)
{
sn_choose[4]=_audio_choose;
AUDIO_PORT.write(sn_choose,6);
delay(100);
}
void audio_reset()
{
AUDIO_PORT.write(sn_reset,4);
delay(500);
}
void audio_init(int _audio_init_device,int _audio_init_mode,int _audio_init_vol)
{
AUDIO_PORT.begin(9600);
delay(500);
audio_reset();
audio_device(_audio_init_device);
audio_mode(_audio_init_mode);
audio_vol(_audio_init_vol);
//audio_choose(1);
//audio_pause();
}
视频 |