diff --git a/src/main.cpp b/src/main.cpp index 759aa8e..90d722d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,6 +36,8 @@ int16_t sBuffer[bufferLen]; #define LEDC_DUTY (4095) #define LEDC_FREQUENCY (20000) // Frequency in Hertz. Set frequency at 20 kHz +#define uS_TO_MS_FACTOR 1000 /* Conversion factor for micro seconds to seconds */ + void i2s_install() { // Set up I2S Processor configuration const i2s_config_t i2s_config = { @@ -99,6 +101,8 @@ static void example_ledc_init(void) void setup() { + setCpuFrequencyMhz(80); + // Set up Serial Monitor Serial.begin(115200); Serial.println(" "); @@ -121,6 +125,8 @@ float thresholdMax = 1000; float thresholdMin = 75; float threshold=thresholdMax; +int numberOfSamples = 0; + void loop() { // Get I2S data and place in data buffer @@ -141,25 +147,24 @@ void loop() { mean /= samples_read; if (std::abs(mean) < thresholdMin) { - Serial.print(mean); - Serial.print(" "); - Serial.println(thresholdMin); - delay(1); - return; + return; } + numberOfSamples = 0; + + const auto maxPower = 1024; Serial.print("CONTINUE"); - for(float progress=0; progress<1.0f; progress+=0.001f) { + for(float progress=0; progress<1.0f; progress+=0.000025f) { int dogOnDuty; - if(progress < 0.2) //20% + if(progress < 0.05) { - dogOnDuty = progress * 5 * 1024; - } else if (progress < 0.8) //20% -80% + dogOnDuty = progress * 20 * maxPower; + } else if (progress < 0.95) { - dogOnDuty = 1024; + dogOnDuty = maxPower; } else { - dogOnDuty = 1024 - ((progress - 0.8) * 5 * 1024); + dogOnDuty = maxPower - ((progress - 0.95) * 20 * maxPower); } ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, dogOnDuty));