LCD+Infrared Sensor

code 1
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x27,16,2);
int aval,temp_aval=0;
void setup() {
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("aval = ");
}
void loop() {
aval = analogRead(A0);
if (temp_aval != aval)
{
lcd.setCursor(7,0);
lcd.print(" ");
}
lcd.setCursor(7,0);
lcd.print(aval);
temp_aval = aval;
delay(300);
}
ทดลองพอเอาภาษา C ไปใส่ Arduino จะได้ว่าพอปรับค่า GP2Y0A21YK0F แล้ว LCD จะแสดงค่า aval ออกมา
code 2
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
int aval,temp_aval=0;
void setup()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("aval = ");
}
void loop()
{
aval = analogRead(A0);
if (temp_aval != aval)
{
lcd.setCursor(7,0);
lcd.print(" ");
}
lcd.setCursor(7,0);
lcd.print(aval);
if (aval>400)
{
lcd.setCursor(0,1);
lcd.print("Hi_Pattayatech");
}
else
{
lcd.setCursor(0,1);
lcd.print("-----");
}
temp_aval = aval;
delay(300);
}
ทดลอง
พอเอาภาษา C ไปใส่ Arduino จะได้ว่าพอปรับค่า GP2Y0A21YK0F แล้ว LCD จะแสดงค่า aval ออกมา ถ้าน้อยกว่า 100 จะขึ้นคำว่า Hi_Pattayatech
ความคิดเห็น
แสดงความคิดเห็น