Hi there, I'm trying to mod a sonic screwdriver to do other cool bits but I'm stuck trying to get an arduino uno to loop audio using the PCM library I found here: http://highlowtech.org/?p=1963
Currently the speaker makes the noise repetitively and stops as soon as the button is released, but in between each of the sample loops there's a brief period where nothing is playing. I know it's not the sample because cutting off the audio at different points has the same result. I know it's possible using this library because I found a video of someone using this (who didn't link the code and has been inactive for 3 years, here's the video though: Link). Although I'm not sure if this is a coding error or the speaker turning off and then instantly on again (I have tried with a larger speakers and had the same result) but I've put the code below so if there's any obvious issue, I'd be very grateful for any suggestion. Thanks
Heres a video of what I got: - YouTube
const int input = 2;
int buttonState = 0;
int timer = 0;
const unsigned char sample[] PROGMEM = { LOTS AND LOTS OF NUMBERS HERE };
void setup()
{
pinMode(input,INPUT);
}
void loop()
{
buttonState = digitalRead(input);
while (buttonState == HIGH) {
buttonState = digitalRead(input);
if (timer == 0) {
startPlayback(sample, sizeof(sample));
}
timer++;
delay(1);
if (timer == 200) {
timer = 0;
startPlayback(sample, sizeof(sample));
}
}
stopPlayback();
timer = 0;
}