งานปฏิบัติที่1
โปรแกรม
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
pinMode (0, INPUT);
pinMode (1, INPUT);
pinMode (8, OUTPUT);
pinMode (9, OUTPUT);
lcd.begin(16, 2);
}
void loop()
{
int re=digitalRead (0);
int le=digitalRead (1);
if (re==0)
{ digitalWrite (8, HIGH);
delay(500);
lcd.setCursor(0, 1);
lcd. print(" Motor1 ");
digitalWrite (8, LOW);
}
if (le==0){
digitalWrite (9, HIGH);
delay (500);
lcd.setCursor (0, 1);
lcd.print (" Motor2 ");
}
}
อธิบายการทำงาน
เมื่อเรากดสวิตซ์ที่1 LCD จะขึ้นคำว่า Motor1 และ ถ้ากด สวิตซ์ที่2 LCD จะขึ้นคำว่า Motor2 หากกดค้างทั้งสองสวิตซ์จะขึ้น Motor1 Motor2 สลับกัน
ไม่มีความคิดเห็น:
แสดงความคิดเห็น