小弟我最近剛接觸到arduino,看了許多教程還有機械手臂後一時心血來潮想自己設計一個。原本想用直覺操作的方式控制伺服馬達,在模擬器瘋狂演練也看不出什麼大問題(https://www.tinkercad.com/things/bZYs6ib9LYU) 但實際組裝起來以後問題就出現了==
我剛上傳完程式,開啟獨立供電模塊以後,伺服馬達(們)馬上就瘋狂的亂轉,用來控制的可變電阻好像也沒什麼幫助...
跪求各大神指點我做錯的地方或是我忽略了什麼關鍵點...
程式碼如下↓
#include <Servo.h>
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
Servo servo6;
const int servo1Pin = 3;
const int servo2Pin = 5;
const int servo3Pin = 6;
const int servo4Pin = 9;
const int servo5Pin = 10;
const int servo6Pin = 11;
const int pot1 = 0;
const int pot2 = 1;
const int pot3 = 2;
const int pot4 = 3;
int potValue1;
int potValue2;
int potValue3;
int potValue4;
int potValue5;
int potValue6;
void setup() {
servo1.attach(servo1Pin);
servo2.attach(servo2Pin);
servo3.attach(servo3Pin);
servo4.attach(servo4Pin);
servo5.attach(servo5Pin);
servo6.attach(servo6Pin);
}
void loop() {
potValue1 = analogRead (pot1);
potValue1 = map(potValue1, 0, 1023, 0, 180);
servo1.write(potValue1);
potValue2 = analogRead (pot1);
potValue2 = map(potValue2, 0, 1023, 0, 180);
servo2.write(180-potValue2);
delay(50);
potValue3 = analogRead (pot3);
potValue3 = map(potValue3, 0, 1023, 0, 180);
servo3.write(potValue3);
delay(50);
potValue4 = analogRead (pot4);
potValue4 = map(potValue4, 0, 1023, 0, 180);
servo4.write(potValue4);
delay(50);
potValue5 = analogRead (pot2);
potValue5 = map(potValue5, 0, 1023, 0, 180);
servo5.write(potValue5);
potValue6 = analogRead (pot2);
potValue6 = map(potValue6, 0, 1023, 0, 180);
servo6.write(180-potValue6);
delay(50);
}