Üdv Tisztel Forumozók!
Itt, Ismerkedjünk a címben szereplő MP3 Shieldel!
Elechouse. Arduino USB-SD MP3 Shield.
http://www.elechouse.com/elechouse/inde ... ts_id=2193
Overview
We already designed an Arduino Wave Shield. However, it doesn't support MP3 format. So now here comes Arduino MP3 Shield. This shield is more powerful and flexible. It supports both wave and mp3 format. Both SD card and U-disk are supported directly. Also there is an on-board 64Mbit flash which could store music files.
There is a standard 3.5mm headset jacket on the shield. You could connect with a standard earphone. We also integrate an audio amplifier on the shield. You could connect loudspeaker directly.
Features
• Plug in and play for Arduino
• Control by Serial UART interface or keys onboard.
• Directly drive 32ohm headset.
• On-board Audio Amplifier to drive 3W/4Ω external loudspeaker.
• 32 levels adjustable volume.
• Support FAT16/FAT32 file system.
• Support both SD/SDHC card and U-Disk.
• On board 64MBit SPI-FLASH.
• Support copying audio files from SD card or U-Disk to SPI-FLASH.
• Supporting Sleep Mode.
• Support 16K~320Kbps MP3 files and 8K~44.1KHz sampling rate WAV files (SPI-FLASH only supports MP3 format)
Connection
Plug in and play.
• Manual
http://www.elechouse.com/elechouse/imag ... 0Guide.pdf
Részlet
Music Order
All the music files must be stored in the root directory of SD or U-disk. Any file name is not restricted as long as it obeys FAT file system.
FAT32 file system has a rule. File order is decided by the file address. File which is created or copied into file system earlier has a higher priority.
The Arduino MP3 Shield plays music in that order. To control the music order in which Arduino MP3 Shield plays, we need to control the order in which the music files are saved in SD or U-disk. For example, you could save music one by one to SD card. You save B.mp3 first and then save A.mp3. By default, it will play B.mp3 fore A.mp3 file.
There is a simple way to save music as desired in bulk:
Create a folder on PC and copy all music files to the folder. Add prefix 0000~9999 to the file names like 0000-God is a girl.mp3, 0001- Baby.mp3, 0002-Set Fire To the Rain.mp3 and so on. Then reorder the music by name. Select all files (CTRL+A may help), then copy (CTRL+C may help), and paste these file to the SD card/U-disk. In this way, the music files will be stored in the desired order.
• Library for Arduino
http://www.elechouse.com/elechouse/imag ... se.com.zip
Elechouse. Arduino USB-SD MP3 Shield.
Re: Elechouse. Arduino USB-SD MP3 Shield.
Bővítettem az eredeti lib-et a hiányzó Check Comands + Rutinokkal!
És némi alkalmazás demóval.
MP3.h
MP3.cpp
És némi alkalmazás demóval.
MP3.h
Kód: Egész kijelölése
/*****************************************************************************/
/**
@file MP3.h
@author ELECHOUSE
@version V0.2
@brief head file for Arduino MP3 Shield
@section HISTORY
V0.2 2012-12-13 Add software serial support.
V0.1 2012-08-02 Initial version.
Copyright (c) 2012 www.elechouse.com All right reserved.
*/
/*****************************************************************************/
#ifndef __MP3_H
#define __MP3_H
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include "wiring_private.h"
#include "SoftwareSerial.h"
#ifndef __TYPE_REDEFINE
#define __TYPE_REDEFINE
/*
typedef uint8_t u8;
typedef int8_t s8;
typedef uint16_t u16;
typedef int16_t s16;
typedef uint32_t u32;
typedef int32_t s32;
*/
#endif
/** Serial port definition */
#define COM Serial
#define SOURCE_NO 0
#define SOURCE_SD 1
#define SOURCE_USB 2
#define SOURCE_FLASH 3
#define MAX_VOLUME 31
/** Check Work State
RETURN VALUE: 0x01 Playing,
0x02 Stop,
0x03 Pause */
#define PLAYING 1
#define STOP 2
#define PAUSE 3
/** set mode, Use SINGLE, REPEAT, CYCLE or RANDOM as parameter
0x00 Single Play
0x01 Repeat single music
0x02 Repeat all
0x03 Play random*/
#define SINGLE_PLAY 0
#define REPEAT_SINGLE_PLAY 1
#define REPEAT_ALL_PLAY 2
#define RANDOM_PLAY 3
#define NEXT_PLAY 5
#define STOP_PLAY 6
#define PAUSE_PLAY 7
#define VOLUME_PLAY 8
typedef enum{
MP3_HARDWARE_SERIAL,
MP3_SOFTWARE_SERIAL
}serial_type_t;
class MP3{
public:
/** constructor */
MP3();
/** begin function, Arduino style */
void begin(serial_type_t st=MP3_HARDWARE_SERIAL );
/** MP3 shield basic send command function */
void send_cmd(u8 *cmd);
/** play music in SD, and choose SD mode */
void play_sd(u16 num);
/** play music in USB, and choose USB mode */
void play_usb_disk(u16 num);
/** play music in SPI FLASH */
void play_spi_flash(u16 num);
/** play next music */
void next();
/** play previous music */
void previous();
/** pause when play, play when pause */
void pause();
/** stop playing */
void stop();
/** set volume */
void volume(u8 vol);
/** set mode, Use SINGLE, REPEAT, CYCLE or RANDOM as parameter */
void set_mode(u8 mode);
enum {SINGLE=0, REPEAT=1, CYCLE=2, RANDOM=3};
/** copy files from SD to SPI FLASH */
void sd_to_flash(void);
/** copy files from USB to SPI FLASH */
void usb_to_flash(void);
// Check Comands +
/** Check Volume Hangerő beállítás lekérdezése */
u8 Check_Volume(void);
/** Check Work State Státus lekérdezése
RETURN VALUE 0x01 Playing, 0x02 Stop, 0x03 Pause */
u8 Check_Work_State(void);
/** Check Total Number SD SD levő filek számának lekérdezése */
u16 Check_Total_Number_SD(void);
/** Check Total Number USB USB levő filek számának lekérdezése */
u16 Check_Total_Number_USB(void);
/** Check Total Number FLASH FLASH ban levő filek számának lekérdezése */
u16 Check_Total_Number_FLASH(void);
/** Check Source az éppen játszott szám forrása és files Number lekérdezése */
u32 Check_Source(void);
/** Check Current Playing File */
u16 Check_Current_Playing_File(void);
/** Get user-defined data */
u32 Get_UserDdefined_Data(void);
private:
/** command buffer */
enum {CMD_BUF_LEN = 10};
u8 cmd_buf[CMD_BUF_LEN];
serial_type_t serial_type;
unsigned long waitTime[2], wait0, wait1;
u8 source;
};
#endif
Kód: Egész kijelölése
/*****************************************************************************/
/**
@file MP3.cpp
@author ELECHOUSE
@version V0.2
@brief head file for Arduino MP3 Shield
@section HISTORY
V0.2 2012-12-13 Add software serial support.
V0.1 2012-08-02 Initial version.
Copyright (c) 2012 www.elechouse.com All right reserved.
@modified kapu48 2016 02.
Added: Check Comands + Rutines.
*/
/*****************************************************************************/
#include "MP3.h"
SoftwareSerial COM_SOFT(7, 8);
MP3::MP3()
{
serial_type_t st=MP3_HARDWARE_SERIAL;
}
/** begin function, Arduino style */
void MP3::begin(serial_type_t st)
{
delay(3000);
serial_type = st;
if(serial_type == MP3_HARDWARE_SERIAL){
COM.begin(9600);
}else{
COM_SOFT.begin(9600);
}
source = SOURCE_NO;
}
/** MP3 shield basic send command function */
void MP3::send_cmd(u8 *cmd)
{
u8 i;
u8 length;
length = cmd[1]+2;
if(length>CMD_BUF_LEN){
return;
}
cmd[0] = 0x7E;
cmd[length-1] = 0x7E;
for(i=0; i<length; i++){
if(serial_type == MP3_HARDWARE_SERIAL){
COM.write(cmd[i]);
}else{
COM_SOFT.write(cmd[i]);
}
}
}
/** play next music */
void MP3::next()
{
cmd_buf[1]=0x02;
cmd_buf[2]=0xA5;
send_cmd(cmd_buf);
}
/** pause when play, play when pause */
void MP3::pause()
{
cmd_buf[1]=0x02;
cmd_buf[2]=0xA3;
send_cmd(cmd_buf);
}
/** stop playing */
void MP3::stop()
{
cmd_buf[1]=0x02;
cmd_buf[2]=0xA4;
send_cmd(cmd_buf);
}
/** play music in SD, and choose SD mode */
void MP3::play_sd(u16 num)
{
cmd_buf[1]=0x04;
cmd_buf[2]=0xA0;
cmd_buf[3]=(u8)(num>>8);
cmd_buf[4]=(u8)num;
send_cmd(cmd_buf);
source = SOURCE_SD;
}
/** play music in SPI FLASH */
void MP3::play_spi_flash(u16 num)
{
cmd_buf[1]=0x04;
cmd_buf[2]=0xA1;
cmd_buf[3]=(u8)(num>>8);
cmd_buf[4]=(u8)num;
send_cmd(cmd_buf);
source = SOURCE_FLASH;
}
/** play music in USB, and choose USB mode */
void MP3::play_usb_disk(u16 num)
{
cmd_buf[1]=0x04;
cmd_buf[2]=0xA2;
cmd_buf[3]=(u8)(num>>8);
cmd_buf[4]=(u8)num;
send_cmd(cmd_buf);
source = SOURCE_USB;
}
/** set volume */
void MP3::volume(u8 vol)
{
cmd_buf[1]=0x03;
cmd_buf[2]=0xA7;
cmd_buf[3]=vol&0x01F;
send_cmd(cmd_buf);
}
/** set mode, Use SINGLE, REPEAT, CYCLE or RANDOM as parameter */
/*
0x00 Single Play
0x01 Repeat single music
0x02 Repeat all
0x03 Play random */
void MP3::set_mode(u8 mode)
{
cmd_buf[1]=0x03;
cmd_buf[2]=0xA9;
cmd_buf[3]=mode;
send_cmd(cmd_buf);
}
/** copy files from SD to SPI FLASH */
void MP3::sd_to_flash(void)
{
cmd_buf[1]=0x03;
cmd_buf[2]=0xAA;
cmd_buf[3]=0;
send_cmd(cmd_buf);
}
/** copy files from USB to SPI FLASH */
void MP3::usb_to_flash(void)
{
cmd_buf[1]=0x03;
cmd_buf[2]=0xAB;
cmd_buf[3]=0;
send_cmd(cmd_buf);
}
/**
Reading Command
Reading command means commands which check the state of Arduino MP3 Shield.
*/
/** Check Volume Hangerő beállítás lekérdezése */
u8 MP3::Check_Volume(void)
{
u8 number, comand;
wait0 = 1;
while (COM_SOFT.available() > 0) { // Kiszedjük az esetleg bent maradt byteket
comand = (u8)COM_SOFT.read();
}
cmd_buf[1]=0x02; // Indítja a parancsot
cmd_buf[2]=0xC1;
send_cmd(cmd_buf);
waitTime[0] = millis() + wait0;
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
comand = (char)COM_SOFT.read();
waitTime[0] = millis() + wait0;
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
number = COM_SOFT.read();
return number;
}
/* Check Work State Státus lekérdezése
RETURN VALUE: 0x01 Playing,
0x02 Stop,
0x03 Pause */
u8 MP3::Check_Work_State(void)
{
u8 number, comand;
wait0 = 1;
while (COM_SOFT.available() > 0) { // Kiszedjük az esetleg bent maradt byteket
comand = (u8)COM_SOFT.read();
}
comand = 0;
cmd_buf[1]=0x02;
cmd_buf[2]=0xC2;
send_cmd(cmd_buf);
waitTime[0] = millis() + wait0;
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
comand = (char)COM_SOFT.read();
//
waitTime[0] = millis() + wait0;
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
number = (char)COM_SOFT.read();
//
return number;
}
/** Check Total Number SD SD levő filek számának lekérdezése */
u16 MP3::Check_Total_Number_SD(void)
{
u16 number ;
u8 comand, j;
wait0 = 1;
while (COM_SOFT.available() > 0) { // Kiszedjük az esetleg bent maradt byteket
comand = (u8)COM_SOFT.read();
}
comand = 0;
cmd_buf[1]=0x02;
cmd_buf[2]=0xC4;
send_cmd(cmd_buf);
//while hurok folyamatosan, és végtelenül,
//amíg a kifejezés a zárójelek () hamissá válik
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
comand = (char)COM_SOFT.read();
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
j = (char)COM_SOFT.read();
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
number = (char)COM_SOFT.read();
number += (u16)j << 8;
return number;
}
/** Check Total Number USB USB levő filek számának lekérdezése */
u16 MP3::Check_Total_Number_USB(void)
{
u16 number;
u8 comand,j;
wait0 = 1;
while (COM_SOFT.available() > 0) { // Kiszedjük az esetleg bent maradt byteket
comand = (u8)COM_SOFT.read();
}
comand = 0;
cmd_buf[1]=0x02;
cmd_buf[2]=0xC5;
send_cmd(cmd_buf);
//while hurok folyamatosan, és végtelenül,
//amíg a kifejezés a zárójelek () hamissá válik
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
comand = (char)COM_SOFT.read();
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
j = (char)COM_SOFT.read();
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
number = (char)COM_SOFT.read();
number += (u16)j << 8;
return number;
}
/** Check Total Number FLASH FLASH - ban levő filek számának lekérdezése */
u16 MP3::Check_Total_Number_FLASH(void)
{
u16 number;
u8 comand,j;
wait0 = 1;
while (COM_SOFT.available() > 0) { // Kiszedjük az esetleg bent maradt byteket
comand = (u8)COM_SOFT.read();
}
comand = 0;
cmd_buf[1]=0x02;
cmd_buf[2]=0xC3;
send_cmd(cmd_buf);
waitTime[0] = wait0 + millis();
//while hurok folyamatosan, és végtelenül,
//amíg a kifejezés a zárójelek () hamissá válik
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
comand = (char)COM_SOFT.read();
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
j = (char)COM_SOFT.read();
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
number = (char)COM_SOFT.read();
number += (u16)j << 8;
return number;
}
/** Check Source az éppen játszott szám forrása és files Number lekérdezése
Lekérdezi az aktuális tárolón levő fájlok számát.
return: upper u16 source A tároló típusa
lower u16 Number A rajta levő fájlok száma */
u32 MP3::Check_Source(void){
u16 Number;
u32 ret = 0;
switch (source) {
case SOURCE_SD: // 1
Number = Check_Total_Number_SD();
//Serial.print(F("File Number_SD = "));
//Serial.println(Number);
break;
case SOURCE_USB: // 2
Number = Check_Total_Number_USB();
//Serial.print(F("File Number_USB = "));
//Serial.println(Number);
break;
case SOURCE_FLASH: // 3
Number = Check_Total_Number_FLASH();
//Serial.print(F("File Number_FLASH= "));
//Serial.println(Number);
break;
default: // 0
// if nothing else matches, do the default
play_sd(1); // Set SOURCE_SD
delay(2);
Number = Check_Total_Number_SD();
stop();
//Serial.print(F("File Number_SD = "));
//Serial.println(Number);
break;
}
ret = (u32)source << 16;
ret += Number;
return ret;
}
/** Check Current Playing File
Return value: TRACKS HIGH BYTE TRACKS LOW BYTE */
u16 MP3::Check_Current_Playing_File(void){
u16 number;
int comand,j;
wait0 = 1;
while (COM_SOFT.available() > 0) { // Kiszedjük az esetleg bent maradt byteket
comand = (u8)COM_SOFT.read();
}
comand = 0;
cmd_buf[1]=0x02;
cmd_buf[2]=0xC6;
send_cmd(cmd_buf);
waitTime[0] = wait0 + millis();
//while hurok folyamatosan, és végtelenül,
//amíg a kifejezés a zárójelek () hamissá válik
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
comand = (char)COM_SOFT.read(); // első byte értéktelen 0xff?
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
comand = (char)COM_SOFT.read(); // COMMAND
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
j = (char)COM_SOFT.read(); // TRACKS HIGH BYTE
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
number = (char)COM_SOFT.read(); // TRACKS LOW BYTE
number += (u16)j << 8;
return number;
}
/** Get user-defined data iSound.mp3 cfxx xx xx xx//
RETURN VALUE: XX XX XX XX (4 bytes) */
u32 MP3::Get_UserDdefined_Data(void){
u32 number;
int comand,j;
wait0 = 1;
// wait1;
while (COM_SOFT.available() > 0) { // Kiszedjük az esetleg bent maradt byteket
comand = (u8)COM_SOFT.read();
}
comand = 0;
cmd_buf[1]=0x02;
cmd_buf[2]=0xC7;
send_cmd(cmd_buf);
waitTime[0] = wait0 + millis();
//while hurok folyamatosan, és végtelenül,
//amíg a kifejezés a zárójelek () hamissá válik
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
comand = (char)COM_SOFT.read(); //
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
comand = (char)COM_SOFT.read();
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
j = (char)COM_SOFT.read();
number = (u32)j << 24;
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
j = (char)COM_SOFT.read();
number += (u32)j << 16;
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
j = (char)COM_SOFT.read();
number += (u32)j << 8;
waitTime[0] = wait0 + millis();
while (COM_SOFT.available() < 1) {if(waitTime[0] < millis()){break;}}
j = (char)COM_SOFT.read();
number += j;
return number;
}
Re: Elechouse. Arduino USB-SD MP3 Shield.
És készült egy demo HW sorosport-i vezérlő alkalmazás.
MP3Shield_Serial_Interpreter.ino
..............................................................................
@modified: 2016. 02.
By kapu48 HW.Serial interpreter
SW. ver.: Arduino 1.6.7
HW:
http://www.elechouse.com MP3 1.2V Shield test . To Arduino Uno.
Ami tartalmaz pár 2 karakteres parancs értelmezését, és végrehajtását végrehajtó Iterpretert.
A működése röviden:
A parancsokat vesszövel kel elválasztani. Az utolsó parancsot pontosvesszővel kel lezárni!
Kis vagy nagy betük használhatók.
(Igy maradt valami nyoma a szövegben a tördelésnek!)
MP3Shield_Serial_Interpreter.ino
..............................................................................
@modified: 2016. 02.
By kapu48 HW.Serial interpreter
SW. ver.: Arduino 1.6.7
HW:
http://www.elechouse.com MP3 1.2V Shield test . To Arduino Uno.
Ami tartalmaz pár 2 karakteres parancs értelmezését, és végrehajtását végrehajtó Iterpretert.
A működése röviden:
A parancsokat vesszövel kel elválasztani. Az utolsó parancsot pontosvesszővel kel lezárni!
Kis vagy nagy betük használhatók.
Kód: Egész kijelölése
Pl.: us,sp,10; (Jelentése: SOURCE_USB,SINGLE_PLAY,10.file;)
Pl.: sp,10; (Jelentése: SOURCE_SD,SINGLE_PLAY,10.file;)
vo,20; (Jelentése: VOLUME_PLAY,20; Lejátszás hangerő = 20)
st; (Jelentése: STOP_PLAY )
Pl2.: SD,RP,22; (Jelentése: SOURCE_SD,REPEAT_SINGLE_PLAY,22.file;)
VO,31; (Jelentése: VOLUME_PLAY,31; Lejátszás hangerő = 31 MAXvolume)
PA; (Jelentése: PAUSE_PLAY)
PA; (ismétlés Jelentése: CONTINUES_PLAY)
Input HW.Serial to MP3_Interpreter Parancs készlett:
"SD" file SOURCE_SD
"US" file SOURCE_USB
"FL" file SOURCE_FLASH
"SP" SINGLE_PLAY, file num (1 - 9999) (Max 4 karakter!)
"RP" REPEAT_SINGLE_PLAY, file num (1 - 9999) (Max 4 karakter!)
"ST" STOP_PLAY
"PA" PAUSE_PLAY
"VO" VOLUME_PLAY, volume (0 - 31) (Max 2 karakter!)
Re: Elechouse. Arduino USB-SD MP3 Shield.
És az alkalmazás!
MP3Shield_Serial_Interpreter.ino
MP3Shield_Serial_Interpreter.ino
Kód: Egész kijelölése
/* MP3Shield_Serial_Interpreter.ino
//..............................................................................
// Idea: Mohannad Rawashdeh
// @modified: 2016. 02.
// By kapu48 HW.Serial interpreter
//
// SW. ver.: Arduino 1.6.7
//
// HW:
// www.elechouse.com MP3 1.2V Shield test . To Arduino Uno.
// http://www.elechouse.com/elechouse/index.php?main_page=product_info&cPath=168_170&products_id=2193
*/
#include <SoftwareSerial.h>
#include "MP3.h"
// testing 1 file Play times ms.
#define PLAY_TIME 50000
/** define mp3 class */
MP3 mp3;
volatile boolean stringComplete = false; // whether the string is complete
String inputString; // a string to hold incoming data
String inputStringOK; // a string to hold incoming data
uint8_t mp3Source, mp3Comand_, mp3Comand_I, string_I, string_II, var ; // Parancs feldolgozó indexelése
uint16_t mp3Comand_N;
unsigned char i;
uint8_t len;
unsigned long waitTime[2], wait0, wait1; // Multi tasking időzítések
u16 Number_SD, Number_USB, Number_FLASH, File_Number; // Számlálók
u8 Check_State, checkSource, set_volum; // Státus infók
u8 source = SOURCE_SD; // Default Source: 0 = SD, 1 = USB, 2 = FLASH
u16 fi = 1; // Default file
//------------------------------------- setup() -----------------------------------------
void setup() {
// put your setup code here, to run once:
Serial.begin(57600);
// reserve 30 bytes for the inputString:
inputString.reserve(30);
// reserve 30 bytes for the inputStringOK:
inputStringOK.reserve(30);
delay(100);
inputString = "";
inputStringOK = "";
// send an intro:
//Serial.println();
mp3.begin(MP3_SOFTWARE_SERIAL); // select software serial
delay(10);
//MyCheckSource(MAX_VOLUME, PLAY_TIME); // Adat tárolók megléte és tartalmának vizsgálata
/** set volum to the MAX = 31 to MIN = 0 */
mp3.volume(MAX_VOLUME - 6);
/** set mode, Use SINGLE, REPEAT, CYCLE or RANDOM as parameter
0x00 Single Play
0x01 Repeat single music
0x02 Repeat all
0x03 Play random*/
// set MP3 Shield SINGLE mode * /
mp3.set_mode(SINGLE_PLAY);
mp3.stop();
// play music in sd, '0001' for first music * /
//mp3.play_sd(0x0001);
// play music in USB-disk * /
//mp3.play_usb_disk(0x0001);
// play music in SPI FLASH * /
//mp3.play_spi_flash(0x0001);
wait0 = PLAY_TIME; // Játék hossza
wait1 = wait0 / 4;
waitTime[0] = wait0 + millis();
waitTime[1] = wait1 + millis();
Serial.println(F(" Input String?")); // Várja a HW.Serial parancsot!
}
//------------------------------------- loop() -----------------------------------------
void loop() {
// print the string when a newline arrives:
if (stringComplete) { // Ha kaptunk 1 parancsot ?
inputStringOK = inputString;
// Megszakítás rutin felkészítése
inputString = "";
stringComplete = false;
// A parancsokat vesszövel kel elválasztani. Az utolsó parancsot pontosvesszővel kel lezárni!
// Kis vagy nagy betük használhatók.
// Pl.: us,sp,10; (Jelentése: SOURCE_USB,SINGLE_PLAY,10.file;)
// Pl.: sp,10; (Jelentése: SOURCE_SD,SINGLE_PLAY,10.file;)
// vo,20; (Jelentése: VOLUME_PLAY,20; Lejátszás hangerő = 20)
// st; (Jelentése: STOP_PLAY )
// Pl2.: SD,RP,22; (Jelentése: SOURCE_SD,REPEAT_SINGLE_PLAY,22.file;)
// VO,31; (Jelentése: VOLUME_PLAY,31; Lejátszás hangerő = 31 MAXvolume)
// PA; (Jelentése: PAUSE_PLAY)
// PA; (ismétlés Jelentése: CONTINUES_PLAY)
/* Input HW.Serial to MP3_Interpreter Parancs készlett:
"SD" file SOURCE_SD
"US" file SOURCE_USB
"FL" file SOURCE_FLASH
"SP" SINGLE_PLAY, file num (1 - 9999) (Max 4 karakter!)
"RP" REPEAT_SINGLE_PLAY, file num (1 - 9999) (Max 4 karakter!)
"ST" STOP_PLAY
"PA" PAUSE_PLAY
"VO" VOLUME_PLAY, volume (0 - 31) (Max 2 karakter!)
*/
MP3_Interpreter(); // Parancs értelmező, és végrehajtó
Serial.println(F("\n Input String?")); // Várja a következő parancsot!
}
/* // Lejátszás tesztek ídőzítése
if(waitTime[0] < millis()){
waitTime[0] = wait0 + millis();
completePlays(source);
}
// Státus beolvasó teszt
if(waitTime[1] < millis()){
waitTime[1] = wait1 + millis();
/* Check Work State
RETURN VALUE: 0x01 Playing,
0x02 Stop,
0x03 Pause * /
Check_State = mp3.Check_Work_State();
Serial.print(F("132. Check_State = "));
Serial.println(Check_State);
// lejátszás ídőzítés vége
if(Check_State == STOP) waitTime[0] = 0; // 0-ás Várakozás törlése.
}
*/
}
//------------------------------------------- endDigit(void) --------------------------------------------
// Megkeresi a numerikus karakterek végét, és az egészet uint16_t -ra alakítja
boolean endDigit(void){
uint8_t string_I_ = ++string_I, num = 0;
string_II++;
boolean While = 1;
boolean comandError = 0;
do{
if((inputStringOK.substring(string_I, string_II) >= "0") && (inputStringOK.substring(string_I, string_II) <= "9")){
string_I++;
string_II++;
num++;
}else{
While = 0;
}
}while(While);
if(num){ // Volt értékes karakter?
string_I = string_I_;
string_II--;
mp3Comand_N = inputStringOK.substring(string_I, string_II).toInt();
string_I = string_II;
string_II++;
}else{ // ? Nem Numerikus char
comandError = 1;
return comandError;
}
if(inputStringOK.substring(string_I, string_II) == ";") { // ? Parancs vége
var = 0; // Ki léptetés a feldolgozó hurokból
}else if(inputStringOK.substring(string_I, string_II) == ",") { // ? Elválasztó jel
string_I++; // Következő 2 betüs parancs
string_II += 3;
}else{ // Error!
comandError = 1;
}
return comandError;
}
//--------------------------------------------- MP3_Interpreter(void) --------------------------------------
/* MP3_Interpreter:
"SD" file SOURCE_SD
"US" file SOURCE_USB
"FL" file SOURCE_FLASH
"SP" SINGLE_PLAY, file num (Max 4 digit!, 0 - 9999)
"RP" REPEAT_SINGLE_PLAY, file num (Max 4 digit!, 0 - 9999)
"ST" STOP_PLAY
"PA" PAUSE_PLAY
"VO" VOLUME_PLAY, volume (0 - 31) (Max 2 digit!, 0 - 31)
*/
boolean MP3_Interpreter(void){
bool comandError = 0;
string_I = 0;
string_II = 2;
var = 1;
mp3Comand_ = SINGLE_PLAY; // Default parancs
mp3Source = SOURCE_SD; // default Source
mp3Comand_N = 1; // Default Num
// Parancs sor értelmezése
while(var){
if(inputStringOK.substring(string_I, string_II) == "SD") { // SOURCE_SD
mp3Source = SOURCE_SD;
mp3Comand_I++;
string_I += 2; // Következő karakter
string_II++;
if(inputStringOK.substring(string_I, string_II) == ";") { // ? Parancs vége
var = 0; // Ki léptetés a feldolgozó hurokból
}else if(inputStringOK.substring(string_I, string_II) == ",") { // ? Elválasztó jel
string_I++;
string_II += 2;
}else{
var = 0; // Ki léptetés a feldolgozó hurokból
comandError = 1; // Parancs hiba
}
}else if(inputStringOK.substring(string_I, string_II) == "US") { // SOURCE_USB
mp3Source = SOURCE_USB;
mp3Comand_I++;
string_I += 2;
string_II++;
if(inputStringOK.substring(string_I, string_II) == ";") { // ? Parancs vége
var = 0;
}else if(inputStringOK.substring(string_I, string_II) == ",") { // ? Elválasztó jel
string_I++;
string_II += 2;
}else{
var = 0;
comandError = 1;
}
}else if(inputStringOK.substring(string_I, string_II) == "FL") { // SOURCE_FLASH
mp3Source = SOURCE_FLASH;
mp3Comand_I++;
string_I += 2;
string_II++;
if(inputStringOK.substring(string_I, string_II) == ";") { // ? Parancs vége
var = 0;
}else if(inputStringOK.substring(string_I, string_II) == ",") { // ? Elválasztó jel
string_I++;
string_II += 2;
}else{
var = 0;
comandError = 1;
}
}else if(inputStringOK.substring(string_I, string_II) == "SP") { // SINGLE_PLAY, file num
mp3Comand_ = SINGLE_PLAY;
mp3Comand_I++;
string_I += 2;
string_II++;
if(inputStringOK.substring(string_I, string_II) == ";") { // ? Parancs vége
var = 0;
}else if(inputStringOK.substring(string_I, string_II) == ",") { // ? Elválasztó jel
comandError = endDigit();
if(comandError) var = 0;
}else{
var = 0;
comandError = 1;
}
}else if(inputStringOK.substring(string_I, string_II) == "RP") { // REPEAT_SINGLE_PLAY, file num
mp3Comand_ = REPEAT_SINGLE_PLAY;
mp3Comand_I++;
string_I += 2;
string_II++;
if(inputStringOK.substring(string_I, string_II) == ";") { // ? Parancs vége
var = 0;
}else if(inputStringOK.substring(string_I, string_II) == ",") { // ? Elválasztó jel
comandError = endDigit();
if(comandError) var = 0;
}else{
var = 0;
comandError = 1;
}
}else if(inputStringOK.substring(string_I, string_II) == "NE") { // NEXT_PLAY
mp3Comand_ = NEXT_PLAY;
mp3Comand_I++;
string_I += 2;
string_II++;
if(inputStringOK.substring(string_I, string_II) == ";") { // ? Parancs vége
var = 0;
}else if(inputStringOK.substring(string_I, string_II) == ",") { // ? Elválasztó jel
string_I++;
string_II += 2;
}else{
var = 0;
comandError = 1;
}
}else if(inputStringOK.substring(string_I, string_II) == "ST") { // STOP_PLAY
mp3Comand_ = STOP_PLAY;
mp3Comand_I++;
string_I += 2;
string_II++;
if(inputStringOK.substring(string_I, string_II) == ";") { // ? Parancs vége
var = 0;
}else if(inputStringOK.substring(string_I, string_II) == ",") { // ? Elválasztó jel
string_I++;
string_II += 2;
}else{
var = 0;
comandError = 1;
}
}else if(inputStringOK.substring(string_I, string_II) == "PA") { // PAUSE_PLAY
mp3Comand_ = PAUSE_PLAY;
mp3Comand_I++;
string_I += 2;
string_II++;
if(inputStringOK.substring(string_I, string_II) == ";") { // ? Parancs vége
var = 0;
}else if(inputStringOK.substring(string_I, string_II) == ",") { // ? Elválasztó jel
string_I++;
string_II += 2;
}else{
var = 0;
comandError = 1;
}
}else if(inputStringOK.substring(string_I, string_II) == "VO") { // VOLUME_PLAY, volume (0 - 31)
mp3Comand_ = VOLUME_PLAY;
mp3Comand_I++;
string_I += 2;
string_II++;
if(inputStringOK.substring(string_I, string_II) == ";") { // ? Parancs vége
var = 0;
}else if(inputStringOK.substring(string_I, string_II) == ",") { // ? Elválasztó jel
comandError = endDigit();
if(comandError) var = 0;
}else{
var = 0;
comandError = 1;
}
}
}
if(comandError){
return 0; // Error!
}
// Parancs végrehalytása
if(mp3Comand_ == SINGLE_PLAY){
mp3.set_mode(SINGLE_PLAY);
if(mp3Source = SOURCE_SD){
mp3.play_sd(mp3Comand_N);
}else if(mp3Source = SOURCE_USB){
mp3.play_usb_disk(mp3Comand_N);
}else if(mp3Source = SOURCE_FLASH){
mp3.play_spi_flash(mp3Comand_N);
}
}else if(mp3Comand_ == REPEAT_SINGLE_PLAY){
mp3.set_mode(REPEAT_SINGLE_PLAY);
if(mp3Source = SOURCE_SD){
mp3.play_sd(mp3Comand_N);
}else if(mp3Source = SOURCE_USB){
mp3.play_usb_disk(mp3Comand_N);
}else if(mp3Source = SOURCE_FLASH){
mp3.play_spi_flash(mp3Comand_N);
}
}else if(mp3Comand_ == NEXT_PLAY){
mp3.next();
}else if(mp3Comand_ == STOP_PLAY){
mp3.stop();
}else if(mp3Comand_ == PAUSE_PLAY){
mp3.pause();
}else if(mp3Comand_ == VOLUME_PLAY){
mp3.volume((u8)mp3Comand_N);
}
return 1; // OK
}
//-------------------------------------- completePlays() -------------------------------
// A tárolókon levő Összes MP3 lejátszása
void completePlays(u8 _source){
switch (_source) {
case SOURCE_SD:
if(Number_USB >= fi){
mp3.play_usb_disk(fi);
fi ++;
}else{
// play music in sd, '0001' for first music * /
fi = 1;
source = SOURCE_USB;
}
break;
case SOURCE_USB:
if(Number_SD >= fi){
mp3.play_sd(fi);
fi ++;
}else{
fi = 1;
source = SOURCE_FLASH;
}
break;
case SOURCE_FLASH:
if(Number_FLASH >= fi){
mp3.play_spi_flash(fi);
fi ++;
}else{
fi = 1;
source = SOURCE_SD;
}
break;
}
}
//-------------------------------------- MyCheckSource() -------------------------------
// Létrző tárolók lekérdezése, Print Filek száma
void MyCheckSource(u8 volume, u16 time){
mp3.set_mode(SINGLE_PLAY);
mp3.volume(volume);
mp3.play_sd(1);
delay(time);
Number_SD = mp3.Check_Total_Number_SD();
Serial.print(F(" File Number SD = "));
Serial.println(Number_SD);
mp3.stop();
mp3.play_usb_disk(1);
delay(time);
Number_USB = mp3.Check_Total_Number_USB();
Serial.print(F(" File Number USB = "));
Serial.println(Number_USB);
mp3.stop();
mp3.play_spi_flash(1);
delay(time);
Number_FLASH = mp3.Check_Total_Number_FLASH();
Serial.print(F(" File Number FLASH= "));
Serial.println(Number_FLASH);
mp3.stop();
}
//---------------------------------------- serialEvent() -------------------------------------------------
/*
SerialEvent occurs whenever a new data comes in the
hardware serial RX. This routine is run between each
time loop() runs, so using delay inside loop can delay
response. Multiple bytes of data may be available.
http://forum.arduino.cc/index.php?topic=290459.0
SerialEvent jelentkezik, amikor új adat érkezik a
hardver soros RX. Ez a rutin fut egymás között
időhurok () fut, így a késés cikluson belül késleltetheti
válasz. Több bájt adat rendelkezésre állhatnak. */
void serialEvent() {
if(!stringComplete){ // Ha az előző adatot már feldogozta
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
// add it to the inputString:
if(isLowerCase(inChar)) inChar -= 32;
inputString += inChar;
// if the incoming character is a newline, set a flag
// so the main loop can do something about it:
if (inChar == '\n') { // ? New Line
stringComplete = true;
}
}
}
}
Re: Elechouse. Arduino USB-SD MP3 Shield.
Ui.:
Az esetleges hibákért, semmi felellőséget nem válalok!
++ A szokásos licens babla! -:)
Az esetleges hibákért, semmi felellőséget nem válalok!
++ A szokásos licens babla! -:)