极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8893|回复: 1

servo 都沒動作是

[复制链接]
发表于 2012-10-1 16:05:01 | 显示全部楼层 |阅读模式
本帖最后由 lou2382 于 2012-10-26 14:17 编辑

請問大大!
我按照書上輸入下列!善我在com視窗輸入  servo 都沒動作是哪錯了?

  1. #include <Servo.h>

  2. Servo myservo0;
  3. Servo myservo1;
  4. Servo myservo2;
  5. Servo myservo3;
  6. Servo myservo4;
  7. Servo myservo5;

  8. int channel;
  9. int angle;
  10. void setup()
  11. {
  12.   myservo0.attach(4);
  13.   myservo1.attach(5);
  14.   myservo2.attach(6);
  15.   myservo3.attach(7);
  16.   myservo4.attach(8);
  17.   myservo5.attach(9);


  18.   myservo0.write(90);  
  19.   myservo1.write(90);
  20.   myservo2.write(90);
  21.   myservo3.write(90);
  22.   myservo4.write(90);
  23.   myservo5.write(90);


  24.   Serial.begin(9600);
  25. }

  26. void loop()
  27. {
  28.   if (Serial.available())
  29.   {
  30.     if ('#' == Serial.read())
  31.     {
  32.       while(!Serial.available());
  33.       channel=Serial.read();
  34.       while (!Serial.available());

  35.       angle=Serial.read() - 0x30;
  36.       while (!Serial.available());
  37.       angle=(Serial.read() - 0x30) +(angle*10);

  38.       while (!Serial.available());
  39.       angle=(Serial.read() - 0x30) + (angle*10);
  40.       if (angle >180 )
  41.         angle = 90;
  42.     }



  43.     switch(channel)
  44.     {
  45.     case '0':
  46.       myservo0.write(angle);
  47.       // Serial.print(angle);
  48.       break;
  49.     case '1':
  50.       myservo1.write(angle);
  51.       // Serial.print(angle);
  52.       break;
  53.     case '2':
  54.       myservo2.write(angle);
  55.       // Serial.print(angle);
  56.       break;
  57.     case '3':
  58.       myservo3.write(angle);
  59.       // Serial.print(angle);
  60.       break;
  61.     case '4':
  62.       myservo4.write(angle);
  63.       //  Serial.print(angle);
  64.       break;
  65.     case '5':
  66.       myservo5.write(angle);
  67.       // Serial.print(angle);
  68.       break;

  69.     default:
  70.       break;
  71.     }

  72.   }
  73. }
复制代码

回复

使用道具 举报

发表于 2012-10-1 18:57:54 | 显示全部楼层
模拟的串口太多了...2个的话就可能动了~
回复 支持 反对

使用道具 举报

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

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

Archiver|联系我们|极客工坊

GMT+8, 2024-5-2 09:02 , Processed in 0.042230 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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