Page 641 - 3-2
P. 641

const int N = 200;


            // This is what will trigger the led. Its INCREDIBLY squishy based on volume of your source,
            // frequency, etc. You'll just need to get in your environment and look at the serial consolef
            // to start. Then pick something that triggers pleasantly to your eye.
            const float THRESHOLD = 500; 민감도//     ?


            // Again, the highest frequency we can target is SAMPLING_FREQUENCY/2. So Since Arduino is
            // relatively slow in terms of audio, we sample literally as fast as we can
            // This is generally around ~8900hz for a 16mhz Arduino and 4400hz for an 8mhz Arduino.
            // User nicola points out these rates are for stock arduino firmware and that on a board
            // by board basis you can juice the adc rates. For Arduino Uno you could move that rate up to
            // 22khz by adding somthing like this to your setup:
            // _SFR_BYTE(ADCSRA) |= _BV(ADPS2); // Set ADPS2
            // _SFR_BYTE(ADCSRA) &= ~_BV(ADPS1); // Clear ADPS1
            // _SFR_BYTE(ADCSRA) &= ~_BV(ADPS0); // Clear ADPS0
            const float SAMPLING_FREQUENCY = 8900;


            Goertzel goertzel = Goertzel(TARGET_FREQUENCY, N, SAMPLING_FREQUENCY);


            void setup(){
              Serial.begin(9600);
                pinMode(led, OUTPUT);
            }


            void loop()
            {
              goertzel.sample(sensorPin); //Will take n samples


              float magnitude = goertzel.detect(); //check them for target_freq


              if(magnitude>THRESHOLD) //if you're getting false hits or no hits adjust this
               digitalWrite(led, HIGH); //if found, enable led
              else
               digitalWrite(led, LOW);; //if not found, or lost, disable led


              Serial.println(magnitude);
            }












            --------------------------------------


                                                         - 641 -
   636   637   638   639   640   641   642   643   644   645   646