极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 14420|回复: 2

舵机反转,怎么写啊

[复制链接]
发表于 2012-10-9 21:46:43 | 显示全部楼层 |阅读模式
如题,官方的教程都是0-180或者180-0转,我想知道反过来该如何该这程序
// Sweep
// by BARRAGAN <http://barraganstudio.com>
// This example code is in the public domain.


#include <Servo.h>

Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

int pos = 0;    // variable to store the servo position

void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}


void loop()
{
  for(pos = 0; pos < 90; pos += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(10);                       // waits 15ms for the servo to reach the position
  }
  for(pos = 90; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(10);                       // waits 15ms for the servo to reach the position
  }
}
回复

使用道具 举报

发表于 2012-10-10 13:57:09 | 显示全部楼层
你这上半部分是正转,下半部分是反转。还能怎么转?
难道下面这样?一开始就是180度?
int pos = 180;
myservo.write(pos);
for(pos = 180; pos > 0 ; pos -= 1)
{
myservo.write(pos);
}
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-10-10 14:07:17 | 显示全部楼层
麽麽茶㊣ 发表于 2012-10-10 13:57
你这上半部分是正转,下半部分是反转。还能怎么转?
难道下面这样?一开始就是180度?
int pos = 180;

还在研究,舵机上装了机械手,舵机控制起来不是太好
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-26 04:37 , Processed in 0.037776 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表