《倒车雷达》

这是我们今天的作业:倒车雷达。

我们首先看一下这次的作业单:
《倒车雷达》_第1张图片
作业单

再来画图:
《倒车雷达》_第2张图片
线路图

这是程序图:
《倒车雷达》_第3张图片
程序图
float checkdistance_13_12() {
  digitalWrite(13, LOW);
  delayMicroseconds(2);
  digitalWrite(13, HIGH);
  delayMicroseconds(10);
  digitalWrite(13, LOW);
  float distance = pulseIn(12, HIGH) / 58.00;
  delay(10);
  return distance;
}

void setup(){
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  Serial.begin(9600);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
}

void loop(){
  Serial.println(checkdistance_13_12());
  if (checkdistance_13_12() > 0 && checkdistance_13_12() < 10) {
    digitalWrite(13,HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(11,LOW);
    digitalWrite(10,LOW);
    delay(500);
    digitalWrite(13,LOW);
    digitalWrite(12,LOW);
    digitalWrite(11,LOW);
    digitalWrite(10,LOW);
    delay(500);

  } else if (checkdistance_13_12() >= 10 && checkdistance_13_12() < 20) {
    digitalWrite(13,LOW);
    digitalWrite(12,LOW);
    digitalWrite(11,HIGH);
    digitalWrite(10,LOW);
    delay(1000);
    digitalWrite(13,LOW);
    digitalWrite(12,LOW);
    digitalWrite(11,LOW);
    digitalWrite(10,LOW);
    delay(1000);
  } else if (checkdistance_13_12() >= 30) {
    digitalWrite(13,LOW);
    digitalWrite(12,LOW);
    digitalWrite(11,LOW);
    digitalWrite(10,HIGH);
    delay(2000);
    digitalWrite(13,LOW);
    digitalWrite(12,LOW);
    digitalWrite(11,LOW);
    digitalWrite(10,LOW);
  }

}

谢谢大家!

你可能感兴趣的:(《倒车雷达》)