Hey! My name is Andrew, this is my first time posting. I am working on prototyping a synthesizer based off of this thing called the Omnichord made in the 80s. I am using the SparkFun MP3 Shield to handle the audio.
So far, I have 4 buttons that each trigger a different audio sample. I am trying to make it work that if you press button 4 + button 1 simultaneously, then it will trigger a 5th audio sample. I can't get it to work. Any help would be greatly appreciated, here is my code. Thank you!
#include <SPI.h>
#include <SdFat.h>
#include <SFEMP3Shield.h>
#include <Bounce2.h>
#define B_ONE A0
#define B_TWO A1
#define B_THREE A2
#define B_FOUR A3
#define BUTTON_DEBOUNCE_PERIOD 20 //ms
SdFat sd;
SFEMP3Shield MP3player;
Bounce b_One = Bounce();
Bounce b_Two = Bounce();
Bounce b_Three = Bounce();
Bounce b_Four = Bounce();
int8_t current_track = 0;
void setup() {
Serial.begin(9600);
pinMode(B_ONE, INPUT_PULLUP);
pinMode(B_TWO, INPUT_PULLUP);
pinMode(B_THREE, INPUT_PULLUP);
pinMode(B_FOUR, INPUT_PULLUP);
b_One.attach(B_ONE);
b_One.interval(BUTTON_DEBOUNCE_PERIOD);
b_Two.attach(B_TWO);
b_Two.interval(BUTTON_DEBOUNCE_PERIOD);
b_Three.attach(B_THREE);
b_Three.interval(BUTTON_DEBOUNCE_PERIOD);
b_Four.attach(B_FOUR);
b_Four.interval(BUTTON_DEBOUNCE_PERIOD);
if (!sd.begin(9, SPI_HALF_SPEED)) sd.initErrorHalt();
if (!sd.chdir("/")) sd.errorHalt("sd.chdir");
MP3player.begin();
MP3player.setVolume(10, 10);
void loop(){
{
if (b_One.update()) {
if (b_One.read() == LOW) {
MP3player.playTrack(3);
}
if (b_One.read() == HIGH) {
MP3player.stopTrack();
}
}
if (b_Two.update()) {
if (b_Two.read() == LOW) {
MP3player.playTrack(2);
}
if (b_Two.read() == HIGH) {
MP3player.stopTrack();
}
}
if (b_Three.update()) {
if (b_Three.read() == LOW) {
MP3player.playTrack(1);
}
if (b_Three.read() == HIGH) {
MP3player.stopTrack();
}
}
if (b_Four.update()) {
if (b_Four.read() == LOW) {
MP3player.playTrack(4);
}
if (b_Four.read() == HIGH) {
MP3player.stopTrack();
}
}
if (b_Four.update() && b_One.update()) {
if (b_Four.read() == LOW && b_One.read() == LOW)
{
MP3player.playTrack(5);
}
if (b_Four.read() == HIGH && b_One.read() == HIGH) {
MP3player.stopTrack();
}
}
}
}