Long Duration Dog Program
This commit is contained in:
parent
052ed90317
commit
89567f53ad
27
src/main.cpp
27
src/main.cpp
|
@ -36,6 +36,8 @@ int16_t sBuffer[bufferLen];
|
||||||
#define LEDC_DUTY (4095)
|
#define LEDC_DUTY (4095)
|
||||||
#define LEDC_FREQUENCY (20000) // Frequency in Hertz. Set frequency at 20 kHz
|
#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() {
|
void i2s_install() {
|
||||||
// Set up I2S Processor configuration
|
// Set up I2S Processor configuration
|
||||||
const i2s_config_t i2s_config = {
|
const i2s_config_t i2s_config = {
|
||||||
|
@ -99,6 +101,8 @@ static void example_ledc_init(void)
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
|
setCpuFrequencyMhz(80);
|
||||||
|
|
||||||
// Set up Serial Monitor
|
// Set up Serial Monitor
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println(" ");
|
Serial.println(" ");
|
||||||
|
@ -121,6 +125,8 @@ float thresholdMax = 1000;
|
||||||
float thresholdMin = 75;
|
float thresholdMin = 75;
|
||||||
float threshold=thresholdMax;
|
float threshold=thresholdMax;
|
||||||
|
|
||||||
|
int numberOfSamples = 0;
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
|
||||||
// Get I2S data and place in data buffer
|
// Get I2S data and place in data buffer
|
||||||
|
@ -141,25 +147,24 @@ void loop() {
|
||||||
mean /= samples_read;
|
mean /= samples_read;
|
||||||
|
|
||||||
if (std::abs(mean) < thresholdMin) {
|
if (std::abs(mean) < thresholdMin) {
|
||||||
Serial.print(mean);
|
return;
|
||||||
Serial.print(" ");
|
|
||||||
Serial.println(thresholdMin);
|
|
||||||
delay(1);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
numberOfSamples = 0;
|
||||||
|
|
||||||
|
const auto maxPower = 1024;
|
||||||
Serial.print("CONTINUE");
|
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;
|
int dogOnDuty;
|
||||||
if(progress < 0.2) //20%
|
if(progress < 0.05)
|
||||||
{
|
{
|
||||||
dogOnDuty = progress * 5 * 1024;
|
dogOnDuty = progress * 20 * maxPower;
|
||||||
} else if (progress < 0.8) //20% -80%
|
} else if (progress < 0.95)
|
||||||
{
|
{
|
||||||
dogOnDuty = 1024;
|
dogOnDuty = maxPower;
|
||||||
} else
|
} 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));
|
ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, dogOnDuty));
|
||||||
|
|
Loading…
Reference in New Issue