Hund mit Progress
This commit is contained in:
parent
0ed602f61b
commit
052ed90317
46
src/main.cpp
46
src/main.cpp
|
@ -33,7 +33,7 @@ int16_t sBuffer[bufferLen];
|
||||||
#define LEDC_OUTPUT_IO (0) // Define the output GPIO
|
#define LEDC_OUTPUT_IO (0) // Define the output GPIO
|
||||||
#define LEDC_CHANNEL LEDC_CHANNEL_0
|
#define LEDC_CHANNEL LEDC_CHANNEL_0
|
||||||
#define LEDC_DUTY_RES LEDC_TIMER_10_BIT // Set duty resolution to 13 bits
|
#define LEDC_DUTY_RES LEDC_TIMER_10_BIT // Set duty resolution to 13 bits
|
||||||
#define LEDC_DUTY (4095) // Set duty to 50%. ((2 ** 13) - 1) * 50% = 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
|
||||||
|
|
||||||
void i2s_install() {
|
void i2s_install() {
|
||||||
|
@ -118,7 +118,7 @@ void setup() {
|
||||||
|
|
||||||
|
|
||||||
float thresholdMax = 1000;
|
float thresholdMax = 1000;
|
||||||
float thresholdMin = 30;
|
float thresholdMin = 75;
|
||||||
float threshold=thresholdMax;
|
float threshold=thresholdMax;
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
|
@ -140,28 +140,38 @@ void loop() {
|
||||||
// Average the data reading
|
// Average the data reading
|
||||||
mean /= samples_read;
|
mean /= samples_read;
|
||||||
|
|
||||||
// Print to serial plotter
|
if (std::abs(mean) < thresholdMin) {
|
||||||
Serial.print(-threshold);
|
Serial.print(mean);
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
Serial.print(threshold);
|
Serial.println(thresholdMin);
|
||||||
Serial.print(" ");
|
delay(1);
|
||||||
Serial.println(mean);
|
return;
|
||||||
if ( mean < threshold) threshold = std::max(thresholdMin, threshold * 0.9999f);
|
}
|
||||||
|
|
||||||
|
Serial.print("CONTINUE");
|
||||||
|
for(float progress=0; progress<1.0f; progress+=0.001f) {
|
||||||
|
int dogOnDuty;
|
||||||
|
if(progress < 0.2) //20%
|
||||||
|
{
|
||||||
|
dogOnDuty = progress * 5 * 1024;
|
||||||
|
} else if (progress < 0.8) //20% -80%
|
||||||
|
{
|
||||||
|
dogOnDuty = 1024;
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
dogOnDuty = 1024 - ((progress - 0.8) * 5 * 1024);
|
||||||
|
}
|
||||||
|
|
||||||
auto dogOnDuty = std::max(0.0f, threshold - thresholdMin);
|
|
||||||
if(dogOnDuty < 500) dogOnDuty = 1;
|
|
||||||
ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, dogOnDuty));
|
ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, dogOnDuty));
|
||||||
// Update duty to apply the new value
|
// Update duty to apply the new value
|
||||||
ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
|
ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
|
||||||
|
|
||||||
if ( std::abs(mean) > threshold) {
|
|
||||||
// DOG WAKEUP
|
// Print to serial plotter
|
||||||
threshold = thresholdMax;
|
Serial.print(progress*1024);
|
||||||
// Set the LEDC peripheral configuration
|
Serial.print(" ");
|
||||||
// Set duty to 50%
|
Serial.println(dogOnDuty);
|
||||||
//ESP_ERROR_CHECK(ledc_set_duty(LEDC_MODE, LEDC_CHANNEL, LEDC_DUTY));
|
delayMicroseconds(5000);
|
||||||
// Update duty to apply the new value
|
|
||||||
//ESP_ERROR_CHECK(ledc_update_duty(LEDC_MODE, LEDC_CHANNEL));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue