loop()

loop()

หลังจากสร้างฟังก์ชั่นการ setup() เริ่มต้นและตั้งค่าเริ่มต้นแล้วฟังก์ชัน loop () จะระบุการทำงานได้อย่างแม่นยำและ ลูปต่อเนื่องทำให้โปรแกรมของคุณสามารถเปลี่ยนแปลงและตอบสนองได้ ใช้มันเพื่อควบคุม Arduino Board

Example

const int buttonPin = 3;

// setup initializes serial and the button pin
void setup()
{
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
}

// loop checks the button pin each time,
// and will send serial if it is pressed
void loop()
{
  if (digitalRead(buttonPin) == HIGH)
    Serial.write('H');
  else
    Serial.write('L');

  delay(1000);
}

ความคิดเห็น

บทความที่ได้รับความนิยม