#include "servo.h" #include // For `millis()` ServoController::ServoController() { } void ServoController::configure(ServoConfiguration configuration) { openDuration = configuration.openDuration; pressedValue = configuration.pressedValue; releasedValue = configuration.releasedValue; ESP32PWM::allocateTimer(configuration.pwmTimer); servo.setPeriodHertz(configuration.pwmFrequency); servo.attach(configuration.pin); releaseButton(); } void ServoController::pressButton() { servo.write(pressedValue); buttonIsPressed = true; openingEndTime = millis() + openDuration; } void ServoController::releaseButton() { servo.write(releasedValue); buttonIsPressed = false; } void ServoController::loop(uint32_t millis) { if (buttonIsPressed && millis > openingEndTime) { releaseButton(); } }