机器人包老师全国青少年机器人技术等级考试四级超声波小车调试程序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);}