Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: A question about notefreq()

  1. #1
    Junior Member
    Join Date
    May 2018
    Posts
    6

    A question about notefreq()

    I am trying to get a pin high on pin 20 when the program "hears" a frequency of 3000 Hz. The program is putting the readings out to the monitor as expected. The problem that I'm having is: that my "if" statement isn't sending the pin high. Maybe I misunderstand the output from notefreq1.read() but it seems pretty straight forward.

    What am I not seeing?


    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SerialFlash.h>
    
    int LedPin = 20; // LED Pin
    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);
        }
    
    }
    }
    Thanks for any input

  2. #2
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    8,317
    To use as OUTPUT this line should not be commented out:
    void setup() {
    // pinMode (LedPin, OUTPUT);
    Also - there is no loop() code doing a write to that pin? Only in setup() one time?

  3. #3
    Junior Member
    Join Date
    May 2018
    Posts
    6
    Thanks, I actually caught that. To many revisions floating around. Project is complete (and it actually works)

    Thanks again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •