Robofun 機器人論壇

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

arduino 求解直流減速馬達+紅外線遮斷合併

[複製鏈接]
跳轉到指定樓層
1#
發表於 2016-5-16 22:55:17 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
直流馬達 以下

int motor[] = {2, 3};
void setup() {
  Serial.begin(9600);
  for(int i = 0; i < 2; i++){
    pinMode(motor, OUTPUT);
  }
}
void loop() {
  left();
  delay(5000);
  motor_stop();
  right();
  delay(5000);
  motor_stop();
}
void motor_stop(){
  digitalWrite(motor[0], LOW);
  digitalWrite(motor[1], LOW);
  delay(25);
}
void left(){
  digitalWrite(motor[0], LOW);
  digitalWrite(motor[1], HIGH);
}
void right(){
  digitalWrite(motor[0], HIGH);
  digitalWrite(motor[1], LOW);
}





紅外線  以下


void setup(){
  tone(4,3000,1000);
  delay(1000);
  pinMode(10,INPUT);pinMode(9,OUTPUT);
  pinMode(3,INPUT);pinMode(2,OUTPUT);
  pinMode(8,OUTPUT);pinMode(7,OUTPUT);
  Serial.begin(9600);}
  void loop(){
    int irLeft = irDetect(9,10,38000);
    int irRight = irDetect(2,3,38000);
    digitalWrite(8,!irLeft);
    digitalWrite(7,!irLeft);
    Serial.print(irLeft);
    Serial.print(" ");
    Serial.println(irRight);
    delay(100);
}





這次我們專題想做個電扶梯的概念
做個小模組
假設客人(放個公仔)經過一樓,紅外線切斷,馬達運轉
到了二樓,紅外線切斷,馬達停止轉動。
大概是這樣的概念 跪求高手解答
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

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

GMT+8, 2024-4-25 12:04 , Processed in 0.315904 second(s), 8 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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