4
0
Fork 0
mirror of https://github.com/zzzzDev4/IAS-Better-Tea.git synced 2025-04-21 07:31:20 +02:00
firmware/src/SmartServo.cpp
2024-04-27 01:00:18 +02:00

32 lines
590 B
C++

#include "SmartServo.hpp"
SmartServo::SmartServo(int pin)
{
myservo.attach(pin);
}
// Note: This blocks execution until servo finished moving.
void SmartServo::moveServoTo(int pos, int stepSize)
{
int currentPos = myservo.read();
for (int p = currentPos; p < pos; p += stepSize)
{
myservo.write(p);
delay(10);
}
for (int p = currentPos; p > pos; p -= stepSize)
{
myservo.write(p);
delay(10);
}
}
void SmartServo::moveServoToZero()
{
moveServoTo(0, 10);
}
void SmartServo::moveServoTo180()
{
moveServoTo(180, 5);
}