i am trying to controll an mp3 player with arduino uno. My target is "when the button is pressed a led will turn on and the mp3 board should play a specific track"
i connected the TX->RX and RX->TX of both boards and i tested this script
// Esempio 01: accendi il led appena è premuto il pulsante
#define LED 7 // LED connected to the digital pin 7
#define BUTTON 9 // pin input button
int val = 0; // status input pin
void setup() {
pinMode(LED, OUTPUT); // pin as output
pinMode(BUTTON, INPUT); // pin as input
Serial.begin(9600);
}
void loop() {
val = digitalRead(BUTTON); // read the pin value and save it
// control that input is HIGH (button pressed)
if (val == HIGH) {
digitalWrite(LED, HIGH); // led turn on
Serial.write("7E 07 A0 30 31 30 30 31 7E") // play file 001.mp3 in folder advert01
}
else {
digitalWrite(LED, LOW); // led turn off
}
}
// Esempio 01: accendi il led appena è premuto il pulsante
#define LED 7 // LED connected to the digital pin 7
#define BUTTON 9 // pin input button
int val = 0; // status input pin
void setup() {
pinMode(LED, OUTPUT); // pin as output
pinMode(BUTTON, INPUT); // pin as input
Serial.begin(9600);
}
void loop() {
val = digitalRead(BUTTON); // read the pin value and save it
// control that input is HIGH (button pressed)
if (val == HIGH) {
digitalWrite(LED, HIGH); // led turn on
Serial.write("7E 07 A0 30 31 30 30 31 7E"); // play file 001.mp3 in folder advert01
}
else {
digitalWrite(LED, LOW); // led turn off
}
}
maybe i need a MAX232 to interface the arduino to the mp3 module board?
So, incorrectly. The resistor is to provide a current path when the switch is not pressed, not to influence the amount of current that flows when the switch is pressed.
PaulS:
So, incorrectly. The resistor is to provide a current path when the switch is not pressed, not to influence the amount of current that flows when the switch is pressed.
i also added a second button in order to select a specific track to be played by the first button but this script is not working properly.. sometime it doesnt switch or doesnt play anything, sometime works..
// switching mp3 files
#define BUTTON2 2 // pin di input a cui è collegato il pulsante 2
#define LED13 13 // LED collegato al pin digitale 13
#define LED 12 // LED connected to the digital pin 7
#define BUTTON 9 // pin input button
// Variabili globali (tutti interi)
int val2 = 0; // status input pin2
int val = 0; // status input pin9
int statoButton = 0; // stato del pulsante (inizialmente non premuto)
int lastStatoButton = 0; // ultimo stato del pulsante (per ora non premuto)
int countButton = 0; // Conteggio del bottone
// Avvio dell'applicazione
void setup() {
pinMode(LED, OUTPUT); // pin as output
pinMode(LED13, OUTPUT); // pin as output
pinMode(BUTTON, INPUT); // pin as input
pinMode(BUTTON2, INPUT); // imposta il pin digitale come input
Serial.begin(9600);
}
// Avvio del loop
void loop() {
val2 = digitalRead(BUTTON2); // read the pin value and save it
// control that input is HIGH (button pressed)
if (val2 == HIGH) {
// play file 010.mp3 in folder advert01
Serial.write(0x7E);
Serial.write(0x07);
Serial.write(0xA0);
Serial.write(0x30);
Serial.write(0x31);
Serial.write(0x30);
Serial.write(0x31);
Serial.write(0x30);
Serial.write(0x7E);
delay(55);
digitalWrite(LED13, HIGH); // led turn on
}
else {
digitalWrite(LED13, LOW); // led turn off
}
if( val2 )
{
// Aspetto 15ms per far alzare il dito all'utente
delay(15);
// Cambio l'ultimo stato del bottone
if(lastStatoButton==0) lastStatoButton=1;
else lastStatoButton=0;
// Aumento il count del bottone
if(countButton<=3) countButton=countButton+1;
else countButton=0;
}
// In base allo stato del bottone scelgo l'azione del led
switch (countButton)
{
// play file 000.mp3 in folder advert01
case 1:
val = digitalRead(BUTTON); // read the pin value and save it
// control that input is HIGH (button pressed)
if (val == HIGH) {
// play file 000.mp3 in folder advert01
Serial.write(0x7E);
Serial.write(0x07);
Serial.write(0xA0);
Serial.write(0x30);
Serial.write(0x31);
Serial.write(0x30);
Serial.write(0x30);
Serial.write(0x30);
Serial.write(0x7E);
delay(55);
digitalWrite(LED, HIGH); // led turn on
}
else {
digitalWrite(LED, LOW); // led turn off
}
break;
// play file 001.mp3 in folder advert01
case 2:
val = digitalRead(BUTTON); // read the pin value and save it
// control that input is HIGH (button pressed)
if (val == HIGH) {
// play file 001.mp3 in folder advert01
Serial.write(0x7E);
Serial.write(0x07);
Serial.write(0xA0);
Serial.write(0x30);
Serial.write(0x31);
Serial.write(0x30);
Serial.write(0x30);
Serial.write(0x31);
Serial.write(0x7E);
delay(55);
digitalWrite(LED, HIGH); // led turn on
}
else {
digitalWrite(LED, LOW); // led turn off
}
break;
// // play file 002.mp3 in folder advert01
case 3:
val = digitalRead(BUTTON); // read the pin value and save it
// control that input is HIGH (button pressed)
if (val == HIGH) {
// play file 003.mp3 in folder advert01
Serial.write(0x7E);
Serial.write(0x07);
Serial.write(0xA0);
Serial.write(0x30);
Serial.write(0x31);
Serial.write(0x30);
Serial.write(0x30);
Serial.write(0x32);
Serial.write(0x7E);
delay(55);
digitalWrite(LED, HIGH); // led turn on
}
else {
digitalWrite(LED, LOW); // led turn off
}
break;
// // play file 004.mp3 in folder advert01
case 0:
val = digitalRead(BUTTON); // read the pin value and save it
// control that input is HIGH (button pressed)
if (val == HIGH) {
// play file 001.mp3 in folder advert01
Serial.write(0x7E);
Serial.write(0x07);
Serial.write(0xA0);
Serial.write(0x30);
Serial.write(0x31);
Serial.write(0x30);
Serial.write(0x30);
Serial.write(0x34);
Serial.write(0x7E);
delay(55);
digitalWrite(LED, HIGH); // led turn on
}
else {
digitalWrite(LED, LOW); // led turn off
}
break;
}
}