PDA

View Full Version : Audio Shield / FFT / Push Button / Interrupts



rexhex
01-19-2016, 03:51 AM
Hello Forum members,

I am working on a project that is using the audio shield with FFT. At the moment I am working on cycling through different settings with two push buttons set as external interrupts. The buttons are working fine but the FFT stops working when I add them to the code. I was thinking that FFT uses interrupts and by turning a pin into an interrupt for the button its messing the the FFT. Does anyone know what pins are used as interrupts for the FFT with the audio shield? The pins I currently have as push button interrupts are 9 and 17.

Thank you for you time,

Rex

rexhex
01-19-2016, 04:36 AM
I figured it out. Pin 9 is used for the bit clock. I moved that button to pin 8 and all is well. :)

https://www.pjrc.com/teensy/td_libs_AudioOutputI2S.html

PaulStoffregen
01-19-2016, 01:36 PM
Glad you found the problem.

In general, the Bounce library is usually best for pushbuttons. It automatically handles mechanical chatter, which can play havoc with interrupts. All the audio tutorials with pushbuttons use the Bounce library, so there's plenty of code in File > Examples > Audio > Tutorial to follow as examples.

rexhex
01-23-2016, 12:37 AM
I like the bounce library because it makes coding for a push button easy. The reason I started to get into interrupts is that my code is gaining many functions and steps. It would take a while for the program to see when a button was pressed. I am handing the debounce with the quoted code. So far this seems to be working great.


void push1()
{
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
if (interrupt_time - last_interrupt_time > 400){
buttonChange1++;
if (buttonChange1>=5){buttonChange1 = 1;}
}
last_interrupt_time = interrupt_time;
Serial.print("PUSHED button 1 ==");
Serial.println(buttonChange1);
}