欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 8878|回復: 0
打印 上一主題 下一主題
收起左側

arduino 并行控制多個舵機

[復制鏈接]
跳轉到指定樓層
樓主
ID:349082 發表于 2018-6-10 22:42 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
/以15毫秒一步的速度轉動
#include <Servo.h>
Servo servo1; // 建立Servo實例
Servo servo2;
const int servo1Pin = 8;  // servo1 接 Pin 8
const int servo2Pin = 9;  // servo2 接 Pin 9
const int every1 = 15;
const int every2 = 15;
int servo1Target = 0;
int servo2Target = 0;
int servo1Dir = 10;
int servo2Dir = 1;
int posOfServo1 = 90;
int posOfServo2 = 90;
void setup() {
  servo1.attach(servo1Pin, 500, 2500); // pin8,
  servo2.attach(servo2Pin, 500, 2500); // pin9
  Serial.begin(9600);
  servo1.write(posOfServo1);
  servo2.write(posOfServo2);
  Serial.println("2 Servo test");
  delay(500);
}
void loop( ) {
  checkServo1();
  checkServo2();
  if (posOfServo1 > 179)
    servo1Target = 0;
  if (posOfServo1 < 1 )
    servo1Target = 180;
  if (posOfServo2 > 179)
    servo2Target = 0;
  if (posOfServo2 < 1 )
    servo2Target = 180;
}

void checkServo1( ) {
  static uint32_t Timer;
  if (Timer > millis())
    return;
  Timer = millis() + every1;
  if (servo1Target > posOfServo1) {
    posOfServo1 += servo1Dir;
  } else if (servo1Target == posOfServo1) {
    return;
  } else {
    posOfServo1 += -servo1Dir;
  }
  servo1.write(posOfServo1);
}
void checkServo2( ) {
  static uint32_t Timer;
  if (Timer > millis())
    return;
  Timer = millis() + every2;
  if (servo2Target > posOfServo2) {
    posOfServo2 += servo2Dir;
  } else if (servo2Target == posOfServo2) {
    return;
  } else {
    posOfServo2 += -servo2Dir;
  }
  servo2.write(posOfServo2);
}
void checkServo3(){
  //依Servo1,servo2,以同樣方法添加更多舵機
}



分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表