實驗目的
讓一顆燈號閃爍,每隔一秒切換一次燈號。
材料
接線
把 LED 接到 Arduino 板子上,LED 長腳(陽極)接到 pin13,短腳(陰極)接到 GND,如圖:
/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/
void setup() {
// initialize the digital pin as an output.
// Pin 13 has an LED connected on most Arduino boards:
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // set the LED on
delay(1000); // wait for a second
digitalWrite(13, LOW); // set the LED off
delay(1000); // wait for a second
}
int LED_PIN=13; //先定義"LED_PIN"叫13
void setup () {
pinMode (LED_PIN, OUTPUT); // 在初始化之後定義 "LED_PIN=13" 是輸出
}
void loop () {
digitalWrite (LED_PIN, HIGH); // 讓LED輸出高電位點亮
delay (1000); // 等待一秒
digitalWrite (LED_PIN, LOW); //變低電位關閉
delay (1000); // 等待一秒
}
條件1
讓(二顆)燈號閃爍
條件2
閃爍時間(分開)