なお GitHub にアップされていて、こちらからファイルをダウンロードし、Arduino IDE の所定の場所に置くか(例えば C:\Program Files (x86)\Arduino\libraries)zip ファイルをダウンロードし、Arduino IDE で取り込めば、ライブラリが使えるようになります。
いきなりサンプルスケッチですが・・
#include <VarSpeedServo.h>
VarSpeedServo myservo; // create servo object to control a servo
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop() {
myservo.write(180, 30, true); // move to 180 degrees, use a speed of 30, wait until move is complete
myservo.write(0, 30, true); // move to 0 degrees, use a speed of 30, wait until move is complete
}
1行目は、VarSpeedServo.h をインクルードする
3行目は、servo オブジェクトを作る
6行目は、サーボ 9番ピンに接続していることを指定する
10行目と11行目でサーボを動かしていますが、
myservo.write(180, 30, true); // move to 180 degrees, use a speed of 30, wait until move is complete
サーボモーターを現在の位置から、180°の位置まで、30のスピードで動かし、wait する myservo.write(0, 30, true); // move to 0 degrees, use a speed of 30, wait until move is complete
/*
ServoSequence
Reads an analog input, and plays different servo sequences depending on the analog value
This example code is in the public domain.
*/
#include <VarSpeedServo.h>
VarSpeedServo myservo1;
const int servoPin1 = 9; // the digital pin used for the servo
// sequences are defined as an array of points in the sequence
// each point has a position from 0 - 180, and a speed to get to that position
servoSequencePoint slow[] = {{100,20},{20,20},{60,50}}; // go to position 100 at speed of 20, position 20 speed 20, position 60, speed 50
servoSequencePoint twitchy[] = {{0,255},{180,40},{90,127},{120,60}};
const int analogPin = A0;
// the setup routine runs once when you press reset:
void setup() {
myservo1.attach(servoPin1);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(analogPin);
if (sensorValue > 200) {
myservo1.sequencePlay(slow, 3); // play sequence "slowHalf" that has 3 positions, loop and start at first position
} else {
myservo1.sequencePlay(twitchy, 4, true, 2); // play sequence "twitchy", loop, start at third position
}
delay(2); // delay in between reads for analogin stability
}
pca9685を使ってサーボ16動かすまでは できているんですけど これに VanSpeedServo.hを組み合わせると うまく動作しないのですけど (当方まだ初心者です)
Arduino で 4 足歩行ロボットを作ってみるかな – の(5)はもうどこかにアップされてますか?
下のサイト 長らくアップしてませんm(__)m
ご覧いただき、ありがとうございます。
物は出来ているのですけれど、(5)の記事としてはまだまとめきれていないのです。
色々ありますねぇ。重心とかの考え方までお勉強するハメいなったりとか、色々とありましたけど。
母親の介護が始まってしまって、手一杯なのですよ。スミマセン。
VanSpeedServo.h は、記憶の範囲ですが、特に問題なく動かすことができると思うのですけど?
僕も模型大好きですよ。
こんにちわ
ディアゴスティーニのロボゼロ ジャンクを入手しまして そのサーボを利用して6本足スパイダー型ロボットをarduinoで動かす夢見てます サーボは3個*6本足で18個 そのうち16個をpac9685で前足先の2個だけarduinoで直接コントロールの予定です ボディと足は出来てます(3Dプリンターで)かなり大きく 60cm四方あります 今度11月の地域であるホビーショーではどうにか動かしたいですね
https://www.youtube.com/watch?v=WyHYw8GN6cs&list=PLhRrALGqN_5HYa0ZUCsfCxo951A_A1spw&index=6
また よろしくお願いします