机器人包老师全国青少年机器人技术等级考试四级:超声波小车调试程序代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

机器人包老师全国青少年机器人技术等级考试四级超声波小车调试程序intfd=30;intbd=10;voidsetup(){pinMode(1OUTPUT);pinMode(2INPUT);pinMode(12OUTPUT);pinMode(13OUTPUT);Serial.begin(9600);}voidloop(){floatd=checkdistance_1_2();Serial.println(d);if((d=fd-bd)&&(d=fd+bd)){analogWrite(5100);analogWrite(6100);if(dfd){digitalWrite(12HIGH);digitalWrite(13LOW);forward();}elseif(dfd){digitalWrite(12LOW);digitalWrite(13HIGH);backward();}else{digitalWrite(12HIGH);digitalWrite(13HIGH);pause();}}else{digitalWrite(12HIGH);digitalWrite(13HIGH);pause();}}floatcheckdistance_1_2(){digitalWrite(1LOW);delayMicroseconds(2);digitalWrite(1HIGH);delayMicroseconds(10);digitalWrite(1LOW);floatdistance=pulseIn(2HIGH)/58.00;delay(10);returndistance;}voidforward(){analogWrite(8255);analogWrite(70);analogWrite(4255);analogWrite(30);}voidbackward(){analogWrite(80);analogWrite(7255);analogWrite(40);analogWrite(3255);}voidturnleft(){analogWrite(80);analogWrite(70);analogWrite(4255);analogWrite(30);}voidturnright(){analogWrite(8255);analogWrite(70);analogWrite(40);analogWrite(30);}voidrotateleft(){analogWrite(80);analogWrite(7255);analogWrite(4255);analogWrite(30);}voidrotateright(){analogWrite(8255);analogWrite(70);analogWrite(40);analogWrite(3255);}voidpause(){analogWrite(80);analogWrite(70);analogWrite(40);analogWrite(30);}

1 / 5
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功