私はArduinoを使い始めたばかりで、高度なものについてはほとんど何も考えていません。それはかなり簡単なようです。今、私は通常2つのデバイスを統合するのが好きなので、コンピューターのキーボードまたはArduinoボードに接続された2つのハードウェアプッシュボタンでサーボを制御できるかどうか疑問に思いました。
念のため、ArduinoUnoボードを使用しています。これが私が今のところサーボをスイープするために使用しているサンプルコードです
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(11); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 45; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
for(pos = 45; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(10); // waits 15ms for the servo to reach the position
}
}
ここで、コンピューターのキーボードの左/右矢印キーを押してサーボの角度を変更したいとします。どうすればそれを行うことができますか?
または、Arduinoに2つのプッシュボタンを取り付け、1つを押すと、ボタンに応じてサーボが左または右に移動します。ボタンをどのポートに接続しますか?コードサンプルや図は大いに役立ちます!