Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 4576|回復: 7
打印 上一主題 下一主題

請問 用Android控制Arduino+伺服馬達

[複製鏈接]
跳轉到指定樓層
1#
發表於 2012-9-23 15:59:10 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
我試了寫這個程式
不過伺服馬達不是不動
就是自己動 能不能幫忙抓抓問題
#include <MeetAndroid.h>
#include <Servo.h>

// declare MeetAndroid so that you can call functions with it
MeetAndroid meetAndroid;
Servo myservo;

int pos = 0;
void setup()  
{
  // use the baud rate your bluetooth module is configured to
  // not all baud rates are working well, i.e. ATMEGA168 works best with 57600
  Serial.begin(9600);
  
  myservo.attach(11);  // 將 servo 物件對應到 pin 11 連接到伺服機
  meetAndroid.registerFunction(Viewup,'U');
  meetAndroid.registerFunction(Viewdown,'D');

}
void loop()
{
  meetAndroid.receive(); // you need to keep this in your loop() to receive events
}
void Viewup(byte flag, byte numOfValues)
{
  UpDrive();
}

void Viewdown(byte flag, byte numOfValues)
{
  DownDrive();
}
void UpDrive()//伺服馬達向上
  {
    for(pos = 0; pos < 180 ; pos +=1)
   
      myservo.write(pos);
      delay(50);
   
  }
  void DownDrive()//伺服馬達向下
  {
    for(pos = 180; pos >= 1 ; pos -=1)
   
      myservo.write(pos);
      delay(50);
   
  }
2#
發表於 2012-9-23 19:00:41 | 只看該作者
回復 1# ray41121


    你的手機有沒有裝 Amarino 2.0?
3#
 樓主| 發表於 2012-9-23 19:13:21 | 只看該作者
有的 我這個程式是第二個了
第一個是控制戰車前後左右的
都沒問題
4#
發表於 2012-9-23 19:36:15 | 只看該作者
回復 3# ray41121

如果meetAndroid方面沒有問題,
可能就是Servo的問題,
你可以設定Servo描述更清楚在程式裡,加幾行如下:
#include <Servo.h>
int SERVO_1_PIN = 11;
Servo servo1;
int minPulse = 600;   // minimum servo position, us (microseconds)
int maxPulse = 2400;  // maximum servo position, us
boolean servosEnabled = false;  //servo power enabled
void setup()
{
  servo1.attach(SERVO_1_PIN, minPulse, maxPulse);
   servosEnabled = true;
}
5#
 樓主| 發表於 2012-9-24 19:16:01 | 只看該作者
回復 4# vegewell


    謝謝你 我晚點試試看
6#
 樓主| 發表於 2012-9-25 12:41:11 | 只看該作者
還是沒辦法耶
上跟下還是一動也不動
7#
發表於 2012-9-25 18:14:45 | 只看該作者
回復 6# ray41121

可能是伺服馬達電力不夠或接線的問題
當然,如果你已經很會用ARDUINO 控制伺服馬達,
  那就不是伺服馬達的問題,
8#
 樓主| 發表於 2012-9-25 22:23:23 | 只看該作者
我解決了感謝

需要一些小變化
感謝各位
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-9-28 05:13 , Processed in 0.183821 second(s), 8 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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