《超声波避障小车程序(共4页).docx》由会员分享,可在线阅读,更多相关《超声波避障小车程序(共4页).docx(4页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上 int Motor1=8; int Motor2=9; int Motor3=10; int Motor4=11; int in=3; int out=2; int pin1=5; int pin2=6; int pwm=100; void setup() Serial.begin(9600); pinMode(in,INPUT); pinMode(out,OUTPUT); pinMode(Motor1,OUTPUT); pinMode(Motor2,OUTPUT); pinMode(pin1,OUTPUT); pinMode(Motor3,OUTPUT); pin
2、Mode(Motor4,OUTPUT); pinMode(pin2,OUTPUT); void loop() digitalWrite(out,LOW); delayMicroseconds(2); digitalWrite(out,HIGH); delayMicroseconds(10); digitalWrite(out,LOW); float pin=pulseIn(in,HIGH); pin=pin/58.0; if(pin=50) qj(100); else ht(500); zz(250); void qj(int t1) analogWrite(pin1,pwm); digita
3、lWrite(Motor1,LOW); digitalWrite(Motor2,HIGH); analogWrite(pin2,pwm); digitalWrite(Motor3,LOW); digitalWrite(Motor4,HIGH); delay(t1); void ht(int t2) analogWrite(pin1,pwm); digitalWrite(Motor1,HIGH); digitalWrite(Motor2,LOW); analogWrite(pin2,pwm); digitalWrite(Motor3,HIGH); digitalWrite(Motor4,LOW)
4、; delay(t2); void tz(int t3) analogWrite(pin1,0); digitalWrite(Motor1,LOW); digitalWrite(Motor2,LOW); analogWrite(pin2,0); digitalWrite(Motor3,LOW); digitalWrite(Motor4,LOW); delay(t3); void zz(int t4) analogWrite(pin1,pwm); digitalWrite(Motor1,HIGH); digitalWrite(Motor2,LOW); analogWrite(pin2,pwm); digitalWrite(Motor3,LOW); digitalWrite(Motor4,HIGH); delay(t4); void yz(int t5) analogWrite(pin1,pwm); digitalWrite(Motor1,LOW); digitalWrite(Motor2,HIGH); analogWrite(pin2,pwm); digitalWrite(Motor3,HIGH); digitalWrite(Motor4,LOW); delay(t5); 专心-专注-专业