Good morning everyone.
A friend of mine and I have a little problem. We are trying to connect an Arduino Mega 2560 with an electric dartboard and play different 8 bit audio samples depending on which field is hit.
We have already connected the Arduino to the dart boards 8x8 matrix and were able to get the output we wanted.
Then we seperately tried to program the audio samples. For this we used this guide: Arduino audio sampling tutorial (part 1) - YouTube
and it works (we have changed the code for our purposes).
Our problem now is, that as soon as we implement a 3rd audio sample, the program starts to behave weird (even though "only" 30% of the program memory is used).´
The sounds are constantly played without us pressing the button and the sounds are also played in a strange order (something like 1 - 3 - 2 - 3 - 3 - 1 - 3 - 2 - 3 - 3 - 1...) with some distortion noises.
Source Code:
short buttonPin = 53;
short i = 0; //Counter for the length of the Sounds
int y = 0; //Switch case for different sounds
short z = 0; //Variable for Button (1 or 0)
void setup()
{
pinMode(buttonPin, INPUT);
DDRC = 255;
}
void loop()
if(digitalRead(buttonPin) == HIGH && y == 0){
z = 1;
} //If button is pressed sound 1 (hall) will be played because the while loop will be true
while(z == 1 && y == 0){
PORTC = pgm_read_byte(&(hall[i++]));
if(i >= sizeof(hall)){
i = 0;
y = 1;
z = 0;
}
delayMicroseconds(62);
} //Loop for the sound 1 (hall) to be played
if(digitalRead(buttonPin) == HIGH && y == 1){
z = 1;
} //If button is pressed sound 2 (craftUH) will be played because the while loop will be true
while(z == 1 && y == 1){
PORTC = pgm_read_byte(&(craftUH[i++]));
if(i >= sizeof(craftUH)){
i = 0;
y = 2;
z = 0;
}
delayMicroseconds(62);
} //Loop for the sound 2 (craftUH) to be played
if(digitalRead(buttonPin) == HIGH && y == 2){
z = 1;
} //If button is pressed sound 3 (err) will be played because the while loop will be true
while(z == 1 && y == 2){
PORTC = pgm_read_byte(&(err[i++]));
if(i >= sizeof(err)){
i = 0;
y = 0;
z = 0;
}
delayMicroseconds(62);
} //Loop for the sound 3 (err) to be played
}
The sounds (hall, craftUH and err are declared above the whole program like this:
const unsigned char hall[28561] PROGMEM =
{
//some hex code
}
but its 5k lines of hex code, so i dont wanna upload that here)
The funny thing is, that if we simply change "err" in the last while loop to either "hall" or "craftUH" the program will only use 23% of Program memory because the const unsigned char err[] wont be uploaded since its not called in the program. After this everything works fine. The sounds are being played in the order we wanted (1 - 2 - 3 - 1 - 2 - 3 - 1 - 2 -....)
Also it doesnt matter which sound we replace with another as long as we only use 2 different sounds it works in any order.
We try these different cases with one button in order to be able to play different sounds if different parts of the dart board are hit later on. We will then merge our two codes but we are not at this point of the project yet.
If you miss something please just ask for it and i will try my best to give you those information.
I can also upload picture of the curcuit we use later today.
Thank you in advance for your time and your help!
Greetings from Germany
Shokker


