<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 模擬技術(shù) > 設(shè)計(jì)應(yīng)用 > 嵌入式四軸遙控小車開發(fā)(附帶程序)

          嵌入式四軸遙控小車開發(fā)(附帶程序)

          作者: 時間:2012-11-14 來源:網(wǎng)絡(luò) 收藏
          der-image: initial" height=513 alt=photo src="http://www.elecfans.com/uploads/allimg/120621/1546235540-3.jpg" width=410>
          用到的程序就是下面的

          //Author:	HE Qichen//Email:	heqichen(a)gaishi.vicp.net//Website:	http://gaishi.vicp.net//Date:	2011-5-1int status;#define LEFT_SPEED   6#define LEFT_FORWARD  7#define LEFT_BACKWARD  8#define RIGHT_SPEED  10#define RIGHT_FORWARD  11#define RIGHT_BACKWARD  12#define ULTRASONIC_ECHO  3#define ULTRASONIC_TRIG  4#define NORMAL_SPEED  100#define STOP_SPEED  0void setup(){Serial.begin(9600);setupMove();setupUltrasonic();}void loop(){unsigned int d;moveForward();d = readDistance();Serial.println(d, DEC);if (d  700){moveBackward();delay(500);turnLeft();delay(200);}}void moveForward(){analogWrite(LEFT_SPEED, NORMAL_SPEED);digitalWrite(LEFT_BACKWARD, LOW);digitalWrite(LEFT_FORWARD, HIGH);analogWrite(RIGHT_SPEED, NORMAL_SPEED);digitalWrite(RIGHT_BACKWARD, LOW);digitalWrite(RIGHT_FORWARD, HIGH);}void moveBackward(){analogWrite(LEFT_SPEED, NORMAL_SPEED);digitalWrite(LEFT_BACKWARD, HIGH);digitalWrite(LEFT_FORWARD, LOW);analogWrite(RIGHT_SPEED, NORMAL_SPEED);digitalWrite(RIGHT_BACKWARD, HIGH);digitalWrite(RIGHT_FORWARD, LOW);}void turnLeft(){analogWrite(LEFT_SPEED, NORMAL_SPEED);digitalWrite(LEFT_BACKWARD, HIGH);digitalWrite(LEFT_FORWARD, LOW);analogWrite(RIGHT_SPEED, NORMAL_SPEED);digitalWrite(RIGHT_BACKWARD, LOW);digitalWrite(RIGHT_FORWARD, HIGH);}void turnRight(){analogWrite(LEFT_SPEED, NORMAL_SPEED);digitalWrite(LEFT_BACKWARD, LOW);digitalWrite(LEFT_FORWARD, HIGH);analogWrite(RIGHT_SPEED, NORMAL_SPEED);digitalWrite(RIGHT_BACKWARD, HIGH);digitalWrite(RIGHT_FORWARD, LOW);}void moveStop(){analogWrite(LEFT_SPEED, STOP_SPEED);digitalWrite(LEFT_BACKWARD, LOW);digitalWrite(LEFT_FORWARD, LOW);analogWrite(RIGHT_SPEED, STOP_SPEED);digitalWrite(RIGHT_BACKWARD, LOW);digitalWrite(RIGHT_FORWARD, LOW);}void setupMove(){pinMode(LEFT_SPEED, OUTPUT);pinMode(LEFT_FORWARD, OUTPUT);pinMode(LEFT_BACKWARD, OUTPUT);pinMode(RIGHT_SPEED, OUTPUT);pinMode(RIGHT_FORWARD, OUTPUT);pinMode(RIGHT_BACKWARD, OUTPUT);analogWrite(LEFT_SPEED, STOP_SPEED);digitalWrite(LEFT_FORWARD, LOW);digitalWrite(LEFT_BACKWARD, LOW);analogWrite(RIGHT_SPEED, STOP_SPEED);digitalWrite(RIGHT_FORWARD, LOW);digitalWrite(RIGHT_BACKWARD, LOW);}unsigned int readDistance(){int duration;digitalWrite(ULTRASONIC_TRIG, LOW);delayMicroseconds(2);digitalWrite(ULTRASONIC_TRIG, HIGH);delayMicroseconds(5);digitalWrite(ULTRASONIC_TRIG, LOW);// The same pin is used to read the signal from the PING))): a HIGH// pulse whose duration is the time (in microseconds) from the sending// of the ping to the reception of its echo off of an object.duration = pulseIn(ULTRASONIC_ECHO, HIGH);return duration;}void  setupUltrasonic(){pinMode(ULTRASONIC_TRIG, OUTPUT);pinMode(ULTRASONIC_ECHO, INPUT);digitalWrite(ULTRASONIC_TRIG, LOW);}
          linux操作系統(tǒng)文章專題:linux操作系統(tǒng)詳解(linux不再難懂)
          紅外遙控器相關(guān)文章:紅外遙控器原理

          上一頁 1 2 下一頁

          關(guān)鍵詞: 嵌入式 四軸遙控小車

          評論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();