VS1053_play event file with Arduino UNO

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
duta
 
Posts: 11
Joined: Sat Mar 01, 2014 11:25 pm

Re: VS1053_play event file with Arduino UNO

Post by duta »

Dear bill
I want pir input with A0~A3 and paly mp3 01.mp3~04.mp3 with D2 D5 D6 D7.
I edit code and upload and then test it.
but it playing continued not stop.
please give me a hint for me.
thanks.

Code: Select all

 if (analogRead(inputAPin) == HIGH) // PIR detected
{
 digitalWrite(ledAPin, HIGH); // turn LED ON
 musicPlayer.playFullFile("01.mp3");
}
else
{
 digitalWrite(ledAPin, LOW); // turn LED OFF
}
 
  if (analogRead(inputBPin) == HIGH) // PIR detected
{
 digitalWrite(ledBPin, HIGH); // turn LED ON
 musicPlayer.playFullFile("02.mp3");
}
else
{
 digitalWrite(ledBPin, LOW); // turn LED OFF
}
 
 if (analogRead(inputCPin) == HIGH) // PIR detected
{
 digitalWrite(ledCPin, HIGH); // turn LED ON
 musicPlayer.playFullFile("03.mp3");
}
else
{
 digitalWrite(ledCPin, LOW); // turn LED OFF
}
 if (analogRead(inputDPin) == HIGH) // PIR detected
{
 digitalWrite(ledDPin, HIGH); // turn LED ON
 musicPlayer.playFullFile("04.mp3");
}
else
{
 digitalWrite(ledDPin, LOW); // turn LED OFF
}
 
 delay(1);
 }

User avatar
adafruit_support_bill
 
Posts: 88142
Joined: Sat Feb 07, 2009 10:11 am

Re: VS1053_play event file with Arduino UNO

Post by adafruit_support_bill »

it playing continued not stop.
Which track was playing continuously?
Were any of the LEDs lit?

duta
 
Posts: 11
Joined: Sat Mar 01, 2014 11:25 pm

Re: VS1053_play event file with Arduino UNO

Post by duta »

Dear bill
Thanks for your reply.
I wish below pattern.
A0-->D2-->01.mp3
A1-->D5-->02.mp3
A2-->D6-->03.mp3
A3-->D7-->04.mp3

Code: Select all

/*************************************************** 
 This is an example for the Adafruit VS1053 Codec Breakout

 Designed specifically to work with the Adafruit VS1053 Codec Breakout 
 ----> https://www.adafruit.com/products/1381

 Adafruit invests time and resources providing this open source code, 
 please support Adafruit and open-source hardware by purchasing 
 products from Adafruit!

 Written by Limor Fried/Ladyada for Adafruit Industries. 
 BSD license, all text above must be included in any redistribution
 ****************************************************/

// include SPI, MP3 and SD libraries
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>

// define the pins used
//#define CLK 13 // SPI Clock, shared with SD card
//#define MISO 12 // Input data, from VS1053/SD card
//#define MOSI 11 // Output data, to VS1053/SD card
// Connect CLK, MISO and MOSI to hardware SPI pins. 
// See http://arduino.cc/en/Reference/SPI "Connections"

// These can be any pins:
#define RESET 9 // VS1053 reset pin (output)
#define CS 10 // VS1053 chip select pin (output)
#define DCS 8 // VS1053 Data/command select pin (output)
#define CARDCS 4 // Card chip select pin
// DREQ should be an Int pin, see http://arduino.cc/en/Reference/attachInterrupt
#define DREQ 3 // VS1053 Data request, ideally an Interrupt pin
//int buttonApin = 6;
//byte leds = 0;
int ledAPin = 2;
int ledBPin = 5;
int ledCPin = 6; // choose the pin for the LED
int ledDPin = 7; // choose the input pin (for PIR sensor)

int inputEPin = A0;
int inputFPin = A1;
int inputGPin = A2;
int inputHPin = A3;
int pirState = LOW; // we start, assuming no motion detected
int val = 0; 

Adafruit_VS1053_FilePlayer musicPlayer = Adafruit_VS1053_FilePlayer(RESET, CS, DCS, DREQ, CARDCS);

void setup() {
 Serial.begin(9600);
 Serial.println("Adafruit VS1053 Simple Test");

 musicPlayer.begin(); // initialise the music player
 SD.begin(CARDCS); // initialise the SD card
 
 // Set volume for left, right channels. lower numbers == louder volume!
 musicPlayer.setVolume(20,20);
 {
 //pinMode(buttonApin, INPUT_PULLUP);
 pinMode(ledAPin, OUTPUT); // declare LED as output
 pinMode(ledBPin, OUTPUT);
 pinMode(ledCPin, OUTPUT);
 pinMode(ledDPin, OUTPUT);
 pinMode(inputEPin, INPUT);
 pinMode(inputFPin, INPUT);
 pinMode(inputGPin, INPUT);
 pinMode(inputHPin, INPUT);
 
 }
 // Timer interrupts are not suggested, better to use DREQ interrupt!
 //musicPlayer.useInterrupt(VS1053_FILEPLAYER_TIMER0_INT); // timer int

 // If DREQ is on an interrupt pin (on uno, #2 or #3) we can do background
 // audio playing
 musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT); // DREQ int
 
 // Play one file, don't return until complete
 //musicPlayer.playFullFile("01.mp3");
 // Play another file in the background, REQUIRES interrupts!
 //musicPlayer.startPlayingFile("track002.mp3");
}

void loop(){

/* if (Serial.available()) {
 char c = Serial.read();
 
 // if we get an 's' on the serial console, stop!
 if (c == 's') {
 musicPlayer.stopPlaying();
 }
 
 // if we get an 'p' on the serial console, pause/unpause!
 if (c == 'p') {
 if (! musicPlayer.paused()) {
 Serial.println("Paused");
 musicPlayer.pausePlaying(true);
 } else { 
 Serial.println("Resumed");
 musicPlayer.pausePlaying(false);
 }
 }
 }

 delay(1);*/
 
 if (analogRead(inputEPin) == HIGH) // PIR detected
{
 digitalWrite(ledAPin, HIGH); // turn LED ON
musicPlayer.playFullFile("01.mp3");
}
else
{
 digitalWrite(ledAPin, LOW); // turn LED OFF
}
 
  if (analogRead(inputFPin) == HIGH) // PIR detected
{
 digitalWrite(ledBPin, HIGH); // turn LED ON
musicPlayer.playFullFile("02.mp3");
}
else
{
 digitalWrite(ledBPin, LOW); // turn LED OFF
}
 
 if (analogRead(inputGPin) == HIGH) // PIR detected
{
 digitalWrite(ledCPin, HIGH); // turn LED ON
musicPlayer.playFullFile("03.mp3");
}
else
{
 digitalWrite(ledCPin, LOW); // turn LED OFF
}
 if (analogRead(inputHPin) == HIGH) // PIR detected
{
 digitalWrite(ledDPin, HIGH); // turn LED ON
musicPlayer.playFullFile("04.mp3");
}
else
{
 digitalWrite(ledDPin, LOW); // turn LED OFF
}
 
delay(100);
 }
 
if pir_out into A0 play 01.mp3 but play 01.mp3 continuously at no signal on pir_out.
also A1~A3 are same state.
please chack code for me.
Thanks.

User avatar
adafruit_support_bill
 
Posts: 88142
Joined: Sat Feb 07, 2009 10:11 am

Re: VS1053_play event file with Arduino UNO

Post by adafruit_support_bill »

Code: Select all

if (analogRead(inputFPin) == HIGH) // PIR detected
You are using analogRead() to read a digital value. Use digitalRead instead.

Code: Select all

if (digitalRead(inputFPin) == HIGH) // PIR detected

duta
 
Posts: 11
Joined: Sat Mar 01, 2014 11:25 pm

Re: VS1053_play event file with Arduino UNO

Post by duta »

Dear bill
It is running well.
Thanks much.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”