Last active
August 29, 2015 13:59
-
-
Save sh4869/10862832 to your computer and use it in GitHub Desktop.
Arduinoでゆっくりサーボを動かしたい時に使う
This file contains 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 servo;//サーボのインスタンス | |
int i = 0; | |
int val = 0; | |
void setup(){ | |
//サーボの信号線を3番ピンに接続 | |
//(PWMピン以外のピンにも接続可) | |
servo.attach(3); | |
} | |
void loop(){ | |
//サーボ出力 | |
while(i < 120){ | |
delay(10); | |
val = 150 - i; | |
servo.write(val); | |
i++; | |
} | |
i = 0; | |
while(i < 120){ | |
delay(10); | |
val = 30 + i; | |
servo.write(val); | |
i++; | |
} | |
i = 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment