#include SoftwareServo myservo; // create servo object to control a servo #include #define RX 4 // MISO . i reversed them to read and debug #define TX 5 // SCK SoftwareSerial Serial(RX, TX); int pos = 0; bool currentState = 1; // to store state of the slider int i = 0; void setup() { myservo.attach(7); Serial.begin(9600); Serial.println("Hello"); for (i = 0; i<30; ++i){ // 0 angle digitalWrite(7, HIGH); delayMicroseconds(1600); digitalWrite(7, LOW); delayMicroseconds(18400); } } void loop () { if (Serial.available()) { char MasterCommand = Serial.read(); if(MasterCommand == 'F') { if (currentState == 1) { Serial.println("Movingleft"); for (i = 0; i<30; ++i){ // 90 angle digitalWrite(7, HIGH); delayMicroseconds(2000); digitalWrite(7, LOW); delayMicroseconds(18000); } currentState = 0; } else { Serial.println("Movingright"); delay(1000); for (i = 0; i<30; ++i){ // 0 angle digitalWrite(7, HIGH); delayMicroseconds(1600); digitalWrite(7, LOW); delayMicroseconds(18400); } currentState = 1; } } } //if (currentState == 0) //{if (Serial.available()) { // char MasterCommand = Serial.read(); // // if(MasterCommand == 'F') { // Serial.println("Movingright"); // for (pos = 180; pos >= 0 ; pos += 5) { // goes from 0 degrees to 180 degrees // // in steps of 1 degree // myservo.write(pos); // tell servo to go to position in variable 'pos' // delay(15); // waits 15ms for the servo to reach the position // SoftwareServo::refresh(); // currentState == 1; // } // } // } // } }