#include <Servo.h>
Servo servo_pin_12;
Servo servo_pin_7;
Servo servo_pin_5;
int bottonmode = 0;
void setup()
{
pinMode( 3 , INPUT);
digitalWrite( 3 , HIGH ); // bottom
servo_pin_12.attach(12); // servo motor
servo_pin_7.attach(7); // servo motor
servo_pin_5.attach(5); // servo motor
Serial.begin(9600);
}
void loop()
{
Serial.print(digitalRead( 3 ));
if (digitalRead(3) == HIGH) {
if ( bottonmode == 0) {
bottonmode = 1;
} else if ( bottonmode == 1) {
bottonmode = 0; // botton (turn on, turn off)
}
delay(500);
}
if (bottonmode == 1)
{
Serial.println("botton=1");
servo_pin_12.write( 0 );
delay( 1500.0 );
servo_pin_12.write( 180 );
delay( 1000.0 );
servo_pin_7.write( 0 );
delay( 1500.0 );
servo_pin_7.write( 180 );
delay( 1000.0 );
servo_pin_5.write( 160 );
delay( 1500.0 );
servo_pin_5.write( 0 );
delay( 1000.0 ); //above are the rotation of servo motor
//the degrees of the rotation can be changed if the degrees above didn't match the rotation angle of your servo motor
bottonmode = 0 ; // the operation will stop once the rotation finish
}
}