/* Sweep by BARRAGAN This example code is in the public domain. modified 8 Nov 2013 by Scott Fitzgerald http://www.arduino.cc/en/Tutorial/Sweep */ #include unsigned long duration,temp_duration = 0; Servo servo1; // create servo object to control a servo Servo servo2; Servo servo3; Servo servo4; // twelve servo objects can be created on most boards int pos = 0; // variable to store the servo position void setup() { Serial.begin(9600); servo1.attach(9, 0, 180); // attaches the servo on pin 9 to the servo object servo2.attach(8, 0, 180); servo3.attach(7, 0, 180); servo4.attach(6, 0, 180); pinMode(10, INPUT); } void extend () { for (pos = 100; pos <= 180; pos += 1) { // in steps of 1 degree servo1.write(pos); servo2.write(pos); servo3.write(pos); servo4.write(pos); delay(10); } } void retract () { for (pos = 180; pos >= 100; pos -= 1) { servo1.write(pos); servo2.write(pos); servo3.write(pos); servo4.write(pos); delay(10); } } void loop() { temp_duration = duration; duration = pulseIn(10, HIGH); if ((temp_duration/100) != (duration/100) and (duration - temp_duration > 50 ) { Serial.println(duration); if(((duration/100)==12) or ((duration/100)==13) ) { extend(); } else { retract(); } } //Serial.println(duration); //extend(); //retract(); }