欢迎光临散文网 会员登陆 & 注册

lcd

2023-07-05 14:24 作者:改个名字收获幸运  | 我要投稿

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,4,5,6,7);

int analogInPin=A0;


void setup() {

  // put your setup code here, to run once:

  lcd.begin(16,2);

  lcd.clear();

  lcd.setCursor(1,0);

  lcd.print ("welcome");

  lcd.setCursor(1,1);

  lcd.print ("I love arduino");

  delay(2000);

}


void loop() {

  // put your main code here, to run repeatedly:

  int sensorVol=analogRead(analogInPin);

  int voltage=map(sensorVol,0,1023,0,500);

  showVol(voltage);

  delay(100);

}

void showVol(int vol)

{

  int vBai,vShi,vGe;

  vBai=vol/100%10;

  vShi=vol/100%10;

  vGe=vol%10;

  lcd.clear();

  lcd.setCursor(3,0);

  lcd.print ("Voltage is");

  lcd.setCursor(6,1);

  lcd.print (vBai);

  lcd.print (".");

  lcd.print (vShi);

  lcd.print (vGe);

  delay(2000);


}


lcd的评论 (共 条)

分享到微博请遵守国家法律