/* This code will move two servo in two angles and turn LED ON and OFF by pressing two buttons on procesing made by Eidha Alrashdi 5/6/2018 */ #include //add Serial library #include //add Servo library, there is no need to write SoftwareServo because I'm using Atmega328p SoftwareSerial mySerial (1, 0); //indicate the gate Tx and Rx, I didnt write (0,1) because here Im reciving. Servo myservo1;//define first servo Servo myservo2;//define second servo char angle; // its a charctare that will store what serial read. int ser1 = 3;// define that first servo is in pin5 int ser2 = 6;// define that second servo is in pin5 int led =4;// define the les is in pin 4 void setup() { pinMode(led,OUTPUT); myservo1.attach(ser1); myservo2.attach(ser2); mySerial.begin(9600); } void loop() { while (mySerial.available()) { // If data is available to read, angle = mySerial.read(); // read it and store it in angle } if (angle == 'b') { // If a was received myservo1.write(0);// move servo1 to angle 0 myservo2.write(90);// move servo2 to angle 90 digitalWrite(led,HIGH);// turn on the led } else { myservo1.write(90);// move servo1 to angle 90 myservo2.write(0);// move servo2 to angle 0 digitalWrite(led,LOW);// turn off the led } delay(10); // Wait 10 milliseconds for next reading }