Last active
August 31, 2016 07:27
-
-
Save sh4869/3893e0af99bfc12a358803632f664c69 to your computer and use it in GitHub Desktop.
3つのサーボモータを同時に動かす
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<Servo.h> | |
Servo myservo; | |
Servo myservo2; | |
Servo myservo3; | |
int pos = 0; | |
int flag = 0; | |
int sw1 = 1; | |
void setup(){ | |
myservo.attach(9); | |
myservo.attach(10); | |
myservo.attach(11); | |
pinMode(sw1,INPUT); | |
} | |
void loop() { | |
flag = digitalRead(sw1); | |
if( flag == 0 ) { | |
for(pos = 0; pos <= 180; pos = pos+1){ | |
myservo.write(pos); | |
myservo2.write(pos); | |
myservo3.write(pos); | |
delay(10); | |
} | |
for(pos = 180;pos >= 0; pos = pos -1){ | |
myservo.write(pos); | |
myservo2.write(pos); | |
myservo3.write(pos); | |
delay(10); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<Servo.h> | |
Servo myservo; | |
Servo myservo2; | |
Servo myservo3; | |
int pos = 0; | |
int flag = 0; | |
int sw1 = 1; | |
void setup(){ | |
myservo.attach(9); | |
myservo.attach(10); | |
myservo.attach(11); | |
pinMode(sw1,INPUT); | |
} | |
void loop() { | |
flag = digitalRead(sw1); | |
if( flag == 0 ) { | |
for(pos = 0; pos <= 180; pos = pos+1){ | |
myservo.write(pos); | |
myservo2.write(180 - pos); | |
myservo3.write(pos); | |
delay(10); | |
} | |
for(pos = 180;pos >= 0; pos = pos -1){ | |
myservo.write(pos); | |
myservo2.write(180 - pos); | |
myservo3.write(pos); | |
delay(10); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment