2026年2月12日 星期四

[OTTO GO] 馬達校正以及輪流動一顆

 

範例一、90度

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <Arduino.h>
#include <ESP32Servo.h>

// OTTO GO Servo pins
#define SERVO_LLEG 21   // PWM1
#define SERVO_RLEG 22   // PWM2
#define SERVO_LFOOT 4   // PWM3
#define SERVO_RFOOT 14  // PWM4

Servo sLleg, sRleg, sLfoot, sRfoot;

void setup() {
  Serial.begin(115200);

  // 建議把脈寬範圍設保守一點,避免頂住抖動
  // attach(pin, minUs, maxUs)
  sLleg.attach(SERVO_LLEG,  600, 2400);
  sRleg.attach(SERVO_RLEG,  600, 2400);
  sLfoot.attach(SERVO_LFOOT, 600, 2400);
  sRfoot.attach(SERVO_RFOOT, 600, 2400);

  // 全部轉到 90 度
  sLleg.write(90);
  sRleg.write(90);
  sLfoot.write(90);
  sRfoot.write(90);

  Serial.println("All servos -> 90 deg (calibration position).");
}

void loop() {
  // 校正時不做事
}



範例二、每 2 秒輪流動一顆

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <Arduino.h>
#include <ESP32Servo.h>

#define SERVO_LLEG 21
#define SERVO_RLEG 22
#define SERVO_LFOOT 4
#define SERVO_RFOOT 14

Servo s[4];

void setup() {
  Serial.begin(115200);
  int pins[4] = {SERVO_LLEG, SERVO_RLEG, SERVO_LFOOT, SERVO_RFOOT};

  for (int i=0;i<4;i++){
    s[i].attach(pins[i], 600, 2400);
    s[i].write(90);
  }
  Serial.println("All -> 90. Now testing one by one...");
}

void loop() {
  for (int i=0;i<4;i++){
    // 只動第 i 顆
    s[i].write(80); delay(800);
    s[i].write(90); delay(800);
    s[i].write(100);delay(800);
    s[i].write(90); delay(800);
  }
}


沒有留言:

張貼留言