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);
}
}
上一篇: 嵌入式系统和Linux命令知识总结(一)
下一篇: Drools
推荐阅读