Hello Arduino Community!
I am working on a cool project at the moment, using an Arduino Mega and a Wav Trigger to play sounds for a DIY pinball machine!
I am using 22 pins to connect to switches in the pinball machine. 0 thru 17 are connected to bumpers that will make sounds, and pins 18-21 are used to switch between banks of sounds.
All the pins are connected to ground with a 10 ohm resistor, except pin 46 which is being used to communicate to the RX pin on the Wav trigger.
Right now I am having some bugs with my set up.
My main problem is not all samples are being played when triggered! The wiring seems to be ok. I was hoping you could see if there are any errors in my code that you think would be causing this.
#include <AltSoftSerial.h>
#include <wavTrigger.h>
wavTrigger wTrig;
//2D array for holding the track numbers. each bank is each song
int songBank[4][18] = {
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18},
{19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36},
{37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 51, 51, 52, 53, 54},
{55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72}
};
int bank = 0; //what bank we are tunes from
//bank pins are the last 4 in the row
//declare pins
int triggerPin[22] = {0 ,1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22};
//
int pinState[22] = {0};
int prevPinState[22] = {0};
void setup() {
//start talking with the wav trigger
wTrig.start();
//read the pins to see if they have made contact
for (int i = 0; i < 22; i++)
{
pinMode(triggerPin[i], INPUT);
}
Serial.begin(9600);
Serial.print("Starting Program");
}
void loop() {
// put your main code here, to run repeatedly:
for (int i = 0; i < 22; i++)
{
pinState[i] = digitalRead(triggerPin[i]);
if (i < 18 )//song pins
{
if (pinState[i] == HIGH && prevPinState[i] == LOW)
{
wTrig.trackPlayPoly(songBank[bank][i]);
Serial.print("Pin connected ");
Serial.println(i);
}
}
prevPinState[i] = pinState[i];
}
if (pinState[18] == HIGH )
bank = 0;
if (pinState[19] == HIGH)
bank = 1;
if (pinState[20] == HIGH)
bank = 2;
if (pinState[21] == HIGH)
bank = 3;
}
Another issue I am facing is that I can't upload code the the Arduino Mega while the Protoshield Mega is connected or I am faced with the "avrdude: stk500v2_ReceiveMessage(): timeout" error reported on this forum post
When the shield is connected I also can't see any serial prints on my computer, which makes debugging hard.
Thank you very much for your help, let me know if you would like me to clarify something more!
audiotest.ino (1.81 KB)