#include <Servo.h> //引入Servo函式庫
Servo base, head; //宣告Servo物件 base, head
int base_degree = 90; //宣告base_degree變數開始角度
int head_degree = 90; //宣告head _degree變數開始角度
void setup() {
base.attach(10); //把base伺服馬達1的橘黃色信號線連接到數位腳D10
head.attach(11); //把head伺服馬達2的橘黃色信號線連接到數位腳D11
}
void loop() {
int vrx = analogRead(A1);
int vry = analogRead(A2);
base_degree = map(vrx, 0, 1023, 0, 180); //搖桿VRx接到類比腳A1
head_degree = map(vry, 0, 1023, 0, 180); //搖桿VRy接到類比腳A2
base.write(base_degree); //轉動base伺服馬達1
head.write(head_degree); //轉動head伺服馬達2
}
Servo base, head; //宣告Servo物件 base, head
int base_degree = 90; //宣告base_degree變數開始角度
int head_degree = 90; //宣告head _degree變數開始角度
void setup() {
base.attach(10); //把base伺服馬達1的橘黃色信號線連接到數位腳D10
head.attach(11); //把head伺服馬達2的橘黃色信號線連接到數位腳D11
}
void loop() {
int vrx = analogRead(A1);
int vry = analogRead(A2);
base_degree = map(vrx, 0, 1023, 0, 180); //搖桿VRx接到類比腳A1
head_degree = map(vry, 0, 1023, 0, 180); //搖桿VRy接到類比腳A2
base.write(base_degree); //轉動base伺服馬達1
head.write(head_degree); //轉動head伺服馬達2
}
留言
張貼留言