欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: 用arduino實現超聲波測距儀 [打印本頁]

作者: yzy_km    時間: 2025-11-1 00:15
標題: 用arduino實現超聲波測距儀
本帖最后由 yzy_km 于 2025-11-1 00:19 編輯

arduino板子,LCD1602,超聲波模塊
程序如下:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //接LCD1602
const int TrigPin = 8;//接超聲波模塊
const int EchoPin = 9;//接超聲波模塊
float cm;
void setup()
{
  Serial.begin(9600);
  pinMode(TrigPin, OUTPUT);
  pinMode(EchoPin, INPUT);
  lcd.begin(16, 2); //設置LCD
  lcd.print("hello,world!"); //hello,world!顯示在LCD
}
void loop()
{
  digitalWrite(TrigPin, LOW); //
  delayMicroseconds(2);
  digitalWrite(TrigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(TrigPin, LOW);
  cm = pulseIn(EchoPin, HIGH) / 58.0; //將回波時間換算成cm
  cm = (int(cm * 100.0)) / 100.0; //保留兩位小數
  Serial.print("Distance:");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  delay(1000);
  lcd.setCursor(0, 1);
  lcd.print("Dis:");
  lcd.setCursor(5, 1);
  lcd.print(cm);
  lcd.setCursor(11, 1);
   lcd.print("cm");
}





歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1