Hello all,
I’m trying to make an LED come on when a certain frequency comes into the onboard microphone. The following piece of code is a mish-mash but works to at least tell me what frequency the input sound is, but whenever I uncomment the ledMode (x,OUTPUT) the recording stops. Am I doing something screwy or does Pin 13 getting set to OUTPUT somehow screw up the other outputs?
I’m using Teensy 3.2 with soundshield
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
int LedPin = 13; // LED Pin- for Teensy 3.2 with soundshield = Pin 13
int ListenFrequency = 3000; // Threshold frequency
// GUItool: begin automatically generated code
AudioInputI2S i2s1; //xy=352,135
AudioAnalyzeNoteFrequency notefreq1; //xy=600,228
AudioOutputI2S i2s2; //xy=626,144
AudioConnection patchCord1(i2s1, 0, notefreq1, 0);
AudioConnection patchCord2(i2s1, 0, i2s2, 0);
AudioConnection patchCord3(i2s1, 0, i2s2, 1);
AudioControlSGTL5000 sgtl5000_1; //xy=525,305
// GUItool: end automatically generated code
//---------------------------------------------------------------------------------------
void setup() {
// pinMode (LedPin, OUTPUT);
digitalWrite (LedPin, LOW);
AudioMemory(30);
Serial.begin(9600);
sgtl5000_1.enable();
sgtl5000_1.volume(0.6);
sgtl5000_1.inputSelect(AUDIO_INPUT_MIC);
sgtl5000_1.micGain(50);
delay(1000);
/*
* Initialize the yin algorithm's absolute
* threshold, this is good number.
*/
notefreq1.begin(.15);
if (notefreq1.read() >= ListenFrequency){
digitalWrite (LedPin, HIGH);
}
while (notefreq1.read()< ListenFrequency) {
digitalWrite (LedPin, LOW);
}
}
void loop() {
// read back fundamental frequency
if (notefreq1.available()) {
float note = notefreq1.read();
float prob = notefreq1.probability();
int cpuusage = AudioProcessorUsageMax();
Serial.printf("CPUusage: %i | Note: %3.2f | Probability: %.2f\n", cpuusage, note, prob);
}
}