#include Servo myservo; Servo myservo2; // create servo object to control a servo int pos = 0; int pos2= 180; // variable to store the servo position const int stepSize = 10; // define the step size const int maxPos = 180; // maximum servo angle const int minPos = 0; // minimum servo angle void setup() { myservo.attach(D7); myservo2.attach(D6); // attaches the servo on pin 9 to the servo object myservo.write(pos); myservo2.attach(pos2); // set initial position Serial.begin(9600); } void loop() { if (Serial.available() > 0) { // check if data is available to read char command = Serial.read(); // read the incoming byte if (command == '1') { // if the command is '1' pos += stepSize; pos2 -= stepSize; // increase position by stepSize if (pos > maxPos) { // if the position exceeds maxPos pos = maxPos; // set it to maxPos } if (pos2 < minPos) { // if the position exceeds maxPos pos2 = minPos; // set it to maxPos } myservo.write(pos); // move the servo to the new position myservo2.write(pos2); // move the servo to the new position Serial.println(pos); // print the new position } else if (command == '0') { // if the command is '0' pos -= stepSize; // decrease position by stepSize if (pos < minPos) { // if the position falls below minPos pos = minPos; // set it to minPos } pos2 += stepSize; // decrease position by stepSize if (pos2 > maxPos) { // if the position falls below minPos pos2 = maxPos; // set it to minPos } myservo.write(pos); // move the servo to the new position Serial.println(pos); // print the new position myservo2.write(pos2); // move the servo to the new position } } }