I am a college Industrial Design student and very new to using the Arduino. In a group with one other, we are making an interactive bench that will sense someone walking past, call them over, and play a song when they sit on one of the seats. There are three seats we have made with aluminum tape creating a switch when the seat is sat on. We were hoping to get a different song for each seat sat on, and each combination of seats sat on. We have been working on the code all evening but are not sure how to get it all to work or where we are going wrong. We named the tracks 'track000' to 'track007' track 000 being the first call over sound.
If there is anyone who knows how we should approach the coding, or where we could change it, any help would be very much appreciated.
Here is our current code:
#include <SPI.h>
#include <Adafruit_VS1053.h>
#include <SD.h>
// These are the pins used for the music maker shield
#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 attachInterrupt() - Arduino Reference
#define DREQ 3 // VS1053 Data request, ideally an Interrupt pin
Adafruit_VS1053_FilePlayer musicPlayer =
// create shield object!
Adafruit_VS1053_FilePlayer(SHIELD_CS, SHIELD_DCS, DREQ, CARDCS);
int inputPin = A0; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
int val1 = 0;
int val2 = 0;
int val3 = 0;
// Per seat number
int senseSeat1 = A1;
int senseSeat2 = A2;
int senseSeat3 = A3;
int trackToPlay = 0;
void setup() {
Serial.begin(9600);
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"));
SD.begin(CARDCS); // initialise the SD card
// Set volume for left, right channels. lower numbers == louder volume!
musicPlayer.setVolume(10,10);
// 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
// Serial.println(F("Playing track 001"));
// musicPlayer.playFullFile("track001.mp3");
// Play another file in the background, REQUIRES interrupts!
// Serial.println(F("Playing track 002"));
// musicPlayer.startPlayingFile("track002.mp3");
pinMode(inputPin, INPUT); // declare sensor as input
pinMode(senseSeat1, INPUT); // declare sensor as input
pinMode(senseSeat2, INPUT); // declare sensor as input
pinMode(senseSeat3, INPUT); // declare sensor as input
}
void loop(){
val = analogRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
Serial.print("Playing 'Sitdown' file because ");
if (pirState == LOW){
// we have just turned on
Serial.print("motion detected!");
//PLAY "Come sit down" track
Serial.println(F(" Now playing track 000"));
musicPlayer.playFullFile("track000.mp3");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
Serial.println("Nothing yet");
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
delay(500);
}
if (digitalRead(senseSeat1 == HIGH)) {
val1 = 1;
}
if (digitalRead(senseSeat2 == HIGH)) {
val2 = 2;
}
if (digitalRead(senseSeat3 == HIGH)) {
val3 = 4;
}
trackToPlay = val1 + val2 + val3;
if (trackToPlay == 1) {
track001();
}
else if (trackToPlay == 2) {
track002();
}
else if (trackToPlay == 3) {
track003();
}
else if (trackToPlay == 4) {
track004();
}
else if (trackToPlay == 5) {
track005();
}
else if (trackToPlay == 6) {
track006();
}
else if (trackToPlay == 7) {
track007();
}
else Serial.print("No trackToPlay");
}
void track001()
{
Serial.println(F(" Now playing track 001"));
musicPlayer.startPlayingFile("track001.mp3");
}
void track002() {
Serial.println(F(" Now playing track 002"));
musicPlayer.startPlayingFile("track002.mp3");
}
void track003() {
Serial.println(F(" Now playing track 003"));
musicPlayer.startPlayingFile("track003.mp3");
}
void track004() {
Serial.println(F(" Now playing track 004"));
musicPlayer.startPlayingFile("track004.mp3");
}
void track005() {
Serial.println(F(" Now playing track 005"));
musicPlayer.startPlayingFile("track005.mp3");
}
void track006() {
Serial.println(F(" Now playing track 006"));
musicPlayer.startPlayingFile("track006.mp3");
}
void track007() {
Serial.println(F(" Now playing track 007"));
musicPlayer.startPlayingFile("track007.mp3");
}