欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Arduino雷达测高度+lcd显示屏

程序员文章站 2022-07-12 10:21:26
...
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int inputPin=7;
int outputPin=8;
void setup()
{
  Serial.begin(9600);//初始化
  pinMode(inputPin,INPUT);
  pinMode(outputPin,OUTPUT);
  lcd.begin(16,2);
  lcd.print("Welcome");
  delay(1000);  
  char val='9';
 }
 void loop()
 {
    digitalWrite(outputPin,LOW);
    delayMicroseconds(2);
    digitalWrite(outputPin,HIGH);
    delayMicroseconds(10);
    digitalWrite(outputPin,LOW);
    int distance=pulseIn(inputPin,HIGH);
    distance=distance/58;
    lcd.clear();
    lcd.print("Distance");
    lcd.setCursor(0,1);
    lcd.print(distance);
    lcd.print("CM");
    delay(2000);
    char val =Serial.read();
    if(val=="r")
    {
      Serial.println("Hello Arduino");
      Serial.println(val);
      }
  }

相关标签: arduino