Re: MusicMaker shield with touch sensor coding question
Re: MusicMaker shield with touch sensor coding question
Re: MusicMaker shield with touch sensor coding question
and 0 is always displayed with the playing of the file upon my touching the sensor, and 1 is always displayed after I release the sensor. It has never displayed a '1' upon touching the sensor.
Re: MusicMaker shield with touch sensor coding question
Re: MusicMaker shield with touch sensor coding question
Re: MusicMaker shield with touch sensor coding question
Re: MusicMaker shield with touch sensor coding question
Re: MusicMaker shield with touch sensor coding question
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the Serial Monitor.
Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/AnalogReadSerial
*/
// 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 are the pins used for the breakout example
#define BREAKOUT_RESET 9 // VS1053 reset pin (output)
#define BREAKOUT_CS 10 // VS1053 chip select pin (output)
#define BREAKOUT_DCS 8 // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_RESET -1 // VS1053 reset pin (unused!)
#define SHIELD_CS 7 // VS1053 chip select pin (output)
#define SHIELD_DCS 6 // VS1053 Data/command select pin (output)
// These are common pins between breakout and shield
#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
Adafruit_VS1053_FilePlayer musicPlayer =
// create breakout-example object!
//Adafruit_VS1053_FilePlayer(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
// create shield-example object!
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Serial.println("Adafruit VS1053 Simple Test");
if (! musicPlayer.begin()) { // initialise the music player
Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
while (1);
}
Serial.println(F("VS1053 found"));
if (!SD.begin(CARDCS)) {
Serial.println(F("SD failed, or not present"));
while (1); // don't do anything more
}
// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(20,20);
if (! musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT))
Serial.println(F("DREQ pin is not an interrupt pin"));
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
Serial.println(musicPlayer.playingMusic);
int threshold = 200;
int v = 0; //volume
// Only start playing if not already playing
if(sensorValue > threshold)
{
//volume fade in
for (v = 140; v > 19; v--){
musicPlayer.setVolume(v,v);
delay (0);}
Serial.println(F("Playing Sound"));
musicPlayer.startPlayingFile("BFSSUSC3.mp3");
while(analogRead(A0) > threshold)
{
// do nothing
}
}
else // stop playing
{
//volume fade out
for (v = 20; v < 140; v++){
musicPlayer.setVolume(v,v);
delay (10);}
Serial.println(F("Paused"));
musicPlayer.pausePlaying("BFSSUSC3.mp3");
while(analogRead(A0) <= threshold)
musicPlayer.begin();
{
// do nothing
}
}
}
Re: MusicMaker shield with touch sensor coding question
Re: MusicMaker shield with touch sensor coding question
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the Serial Monitor.
Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/AnalogReadSerial
*/
// 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 are the pins used for the breakout example
#define BREAKOUT_RESET 9 // VS1053 reset pin (output)
#define BREAKOUT_CS 10 // VS1053 chip select pin (output)
#define BREAKOUT_DCS 8 // VS1053 Data/command select pin (output)
// These are the pins used for the music maker shield
#define SHIELD_RESET -1 // VS1053 reset pin (unused!)
#define SHIELD_CS 7 // VS1053 chip select pin (output)
#define SHIELD_DCS 6 // VS1053 Data/command select pin (output)
// These are common pins between breakout and shield
#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
Adafruit_VS1053_FilePlayer musicPlayer =
// create breakout-example object!
//Adafruit_VS1053_FilePlayer(BREAKOUT_RESET, BREAKOUT_CS, BREAKOUT_DCS, DREQ, CARDCS);
// create shield-example object!
Adafruit_VS1053_FilePlayer(SHIELD_RESET, SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
Serial.println("Adafruit VS1053 Simple Test");
if (! musicPlayer.begin()) { // initialise the music player
Serial.println(F("Couldn't find VS1053, do you have the right pins defined?"));
while (1);
}
Serial.println(F("VS1053 found"));
if (!SD.begin(CARDCS)) {
Serial.println(F("SD failed, or not present"));
while (1); // don't do anything more
}
// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(20,20);
if (! musicPlayer.useInterrupt(VS1053_FILEPLAYER_PIN_INT))
Serial.println(F("DREQ pin is not an interrupt pin"));
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
Serial.println(musicPlayer.playingMusic);
int threshold = 200;
int v = 0; //volume
// Only start playing if not already playing
if(sensorValue > threshold)
{
//volume fade in
for (v = 140; v > 19; v--){
musicPlayer.setVolume(v,v);
delay (0);}
Serial.println(F("Playing Sound"));
musicPlayer.startPlayingFile("BFSSUSC3.mp3");
while(analogRead(A0) > threshold)
{
// do nothing
}
}
else // stop playing
{
//volume fade out
for (v = 20; v < 140; v++){
musicPlayer.setVolume(v,v);
delay (10);}
Serial.println(F("Paused"));
musicPlayer.pausePlaying("BFSSUSC3.mp3");
while(analogRead(A0) <= threshold)
musicPlayer.begin();
{
// do nothing
}
}
}
Re: MusicMaker shield with touch sensor coding question
Re: MusicMaker shield with touch sensor coding question
Re: MusicMaker shield with touch sensor coding question
Re: MusicMaker shield with touch sensor coding question
Re: MusicMaker shield with touch sensor coding question