四博智联产品售后

标题: 16路舵机控制Arduino示例 [打印本页]

作者: ycf    时间: 2015-12-10 10:54
标题: 16路舵机控制Arduino示例
servo.zip (1.89 KB, 下载次数: 14573)
  1. /***************************************************
  2.   Example for 2 DC motor && 16 Servo Drive Shield.

  3.   Results: Servo run forward, and then backward....

  4.   by DOIT. http://www.doit.am
  5. ****************************************************/

  6. #include <Wire.h>
  7. #include "ServoDriver.h"

  8. ServoDriver pwm = ServoDriver();

  9. #define SERVOMIN  102 // this is the 'minimum' pulse length count (out of 4096)
  10. #define SERVOMAX  512 // this is the 'maximum' pulse length count (out of 4096)

  11. // IMPORTANT: Servo num #
  12. uint8_t servonum = 7;

  13. void setup() {

  14.   pwm.begin();
  15.   pwm.setPWMFreq(50);  // servos run at 50 Hz
  16. }

  17. void loop() {
  18.   // Drive ONE servo  at a time

  19.   for (uint16_t pulselen = SERVOMIN; pulselen < SERVOMAX; pulselen++) {
  20.     pwm.setPWM(servonum, 0, pulselen);
  21.   }
  22.   delay(300);
  23.   for (uint16_t pulselen = SERVOMAX; pulselen > SERVOMIN; pulselen--) {
  24.     pwm.setPWM(servonum, 0, pulselen);
  25.   }
  26.   delay(300);
  27. }
复制代码





欢迎光临 四博智联产品售后 (http://bbs.doit.am/) Powered by Discuz! X3.2