/*
Forum: https://forum.arduino.cc/t/help-with-code-if-possible/1201603
Wokwi: https://wokwi.com/projects/384469230441620481
*/
#include "ServoEasing.hpp"
ServoEasing servotop;
ServoEasing servobottom;
const int action_pin = 2;
int location = 35;
// Below numbers should be adjusted in case the servos does not close/open as desired
int bottom_closed = 107;
int top_closed = 167;
int bottom_open = 20;
int top_open = 20;
void setup()
{
pinMode(action_pin, INPUT_PULLUP);
servotop.attach(7);//missle
servobottom.attach(8);//up and down
setSpeedForAllServos(190);
servotop.setEasingType(EASE_CUBIC_IN_OUT);
servobottom.setEasingType(EASE_CUBIC_IN_OUT);
synchronizeAllServosStartAndWaitForAllServosToStop();
}
void loop()
{
int proximity = digitalRead(action_pin);
if (proximity == LOW)
{
if (location > bottom_open) {
servotop.setEaseTo(top_open);
servobottom.setEaseTo(bottom_open);
synchronizeAllServosStartAndWaitForAllServosToStop();
location = bottom_open;
delay(600);
} else {
servotop.setEaseTo(top_closed);
delay(200);
synchronizeAllServosStartAndWaitForAllServosToStop();
servobottom.setEaseTo(bottom_closed);
location = bottom_closed;
delay(200);
synchronizeAllServosStartAndWaitForAllServosToStop();
servotop.setEaseTo(top_closed);
}
}
};