我正在编写的程序基本上可以让一个人用一个Pieszo传感器连接到他们的鞋子底部来运行/步进,并且相同的bpm相应的轨道将通过连接到Arduino上的MP3shield的小型扬声器播放。这是一个更大概念的原型。
以下是我到目前为止:
// libraries
#include <SPI.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <SFEMP3Shield.h>
#include <SimpleTimer.h>
int knockSensor = 0;
int MINIMUM = 520;
int MAXIMUM = 530;
int counter = 0;
int comparativeBPM;
SdFat sd;
SFEMP3Shield MP3player;
SimpleTimer timer;
String trackLibrary[30] = {track001.mp3, track002.mp3, track003.mp3, track004.mp3, track005.mp3, track006.mp3, track007.mp3, track008.mp3, track009.mp3, track010.mp3, track011.mp3, track012.mp3, track013.mp3, track014.mp3, track015.mp3, track016.mp3, track017.mp3, track018.mp3, track019.mp3, track020.mp3, track021.mp3, track022.mp3, track023.mp3, track024.mp3, track25.mp3, track026.mp3, track027.mp3, track028.mp3, track029.mp3, track030.mp3};
//bpms increases by 1 starting with 151 in the track library above so 151-180
void setup() {
Serial.begin(9600);
timer.setInterval(1000, ticker);
if(!sd.begin(9, SPI_HALF_SPEED)) sd.initErrorHalt();
if (!sd.chdir("/")) sd.errorHalt("sd.chdir");
MP3player.begin();
MP3player.setVolume(10,10);
}
void loop() {
timer.run();
if (analogRead(knockSensor) >= MINIMUM && analogRead(knockSensor) <= MAXIMUM) { //if knock is between maximum and minimum threshold
Serial.println("Step detected"); //print when step detected
counter = knockSensor++; //increment counter every time step detected
Serial.println(counter); //print counter value to test
}
if (timer == 60000) {
comparativeBPM = (counter/60)*3; // divide counter by 60s to get BPM and multply by 3 to get average bpm
if (comparativeBPM >= 151) {
MP3player.playTrack(track001.mp3);
}
if (comparativeBPM == 152) {
MP3player.playTrack(track002.mp3);
}
if (comparativeBPM == 153) {
MP3player.playTrack(track003.mp3);
}
if (comparativeBPM == 154) {
MP3player.playTrack(track004.mp3);
}
if (comparativeBPM == 155) {
MP3player.playTrack(track005.mp3);
}
if (comparativeBPM == 156) {
MP3player.playTrack(track006.mp3);
}
if (comparativeBPM == 157) {
MP3player.playTrack(track007.mp3);
}
if (comparativeBPM == 158) {
MP3player.playTrack(track008.mp3);
}
if (comparativeBPM == 159) {
MP3player.playTrack(track009.mp3);
}
if (comparativeBPM == 160) {
MP3player.playTrack(track010.mp3);
}
if (comparativeBPM == 161) {
MP3player.playTrack(track011.mp3);
}
if (comparativeBPM == 162) {
MP3player.playTrack(track012.mp3);
}
if (comparativeBPM == 163) {
MP3player.playTrack(track013.mp3);
}
if (comparativeBPM == 164) {
MP3player.playTrack(track014.mp3);
}
if (comparativeBPM == 165) {
MP3player.playTrack(track015.mp3);
}
if (comparativeBPM == 166) {
MP3player.playTrack(track016.mp3);
}
if (comparativeBPM == 167) {
MP3player.playTrack(track017.mp3);
}
if (comparativeBPM == 168) {
MP3player.playTrack(track018.mp3);
}
if (comparativeBPM == 169) {
MP3player.playTrack(track019.mp3);
}
if (comparativeBPM == 170) {
MP3player.playTrack(track020.mp3);
}
if (comparativeBPM == 171) {
MP3player.playTrack(track021.mp3);
}
if (comparativeBPM == 172) {
MP3player.playTrack(track022.mp3);
}
if (comparativeBPM == 173) {
MP3player.playTrack(track023.mp3);
}
if (comparativeBPM == 174) {
MP3player.playTrack(track024.mp3);
}
if (comparativeBPM == 175) {
MP3player.playTrack(track025.mp3);
}
if (comparativeBPM == 176) {
MP3player.playTrack(track026.mp3);
}
if (comparativeBPM == 177) {
MP3player.playTrack(track027.mp3);
}
if (comparativeBPM == 178) {
MP3player.playTrack(track028.mp3);
}
if (comparativeBPM == 179) {
MP3player.playTrack(track029.mp3);
}
if (comparativeBPM == 180) {
MP3player.playTrack(track030.mp3);
}
}
timer.restartTimer(timer);
}
}
void ticker() {
Serial.print("Time (s): ");
Serial.println(millis()/1000);
}
如果有人知道这是如何运作的,那么任何帮助都会非常感激。我正在使用的MP3屏蔽是一个SparkfunMP3屏蔽,并在这里附带它自己的参考库https://learn.sparkfun.com/tutorials/mp3-player-shield-hookup
这应该有用,但我对文档知之甚少,无法弄清楚为什么这不起作用!请帮忙