Page 644 - 3-2
P. 644
// 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(){
pinMode(led, OUTPUT);
Serial.begin(9600);
}
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);
}
-----------------------------------------------------------------------------
와이파이 클라이언트 코드
/*
* This sketch sends a message to a TCP server
*
*/
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
ESP8266WiFiMulti WiFiMulti;
WiFiClient client;
- 644 -