lcd
#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);
}
標簽: