Page 170 - เอกสารประกอบการสอนวิชาไมโครคอนโทรลเลอร์เบื้องต้น
P. 170
เอกสารประกอบการสอนวิชาไมโครคอนโทรลเลอร์เบื้องต้น 43
Code
const int buttonPin = 2;
const int ledPin = 13;
int buttonState = 0;
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop()
{
buttonState = digitalRead (buttonPin);
if (buttonState == HIGH)
{
digitalWrite(ledPin, HIGH);
}
//จากนั้นให้เปลี่ยนค่า if (buttonState == HIGH)เป็น if (buttonState == LOW)แล้วสังเกตุผล
ผลการทดลอง
.....................................................................................................................................................................
.....................................................................................................................................................................
.....................................................................................................................................................................
.....................................................................................................................................................................
.....................................................................................................................................................................
.....................................................................................................................................................................
.....................................................................................................................................................................
.....................................................................................................................................................................
.....................................................................................................................................................................
.....................................................................................................................................................................
.....................................................................................................................................................................
.....................................................................................................................................................................
หน่วยที่ 3 โครงสร้างโปรแกรมของ Arduino เรียบเรียงโดยครูทันพงษ์ ภู่รักษ์