Arduino No.03 LED点滅プログラム
1個のLED(発光ダイオード)を点滅させてみる。
単純に、13番とGNDに赤色LEDを接続
接続する時は、極性を注意すること!!
13:LEDの長い方(+)
GND:LEDの短い方(−)
【Program】
void setup() {
//initialize the digital pin as an output
//Pin 13 has on LED connected on most Arduino boords:
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
}
最初に呼ばれる setup() で13番ピンを出力ピンとして設定。
loop() は毎フレーム呼ばれる関数です。
digitalWrite(13, HIGH); で13番ピンをHIGH状態にして、LEDを点灯。
delay(1000); で 1000ms の間スリープ。
digitalWrite(13, LOW); で13番ポートをLOWにしてLEDを消灯。
delay(1000); で1000msスリープ。
【補足】ずっとloopするの、なんか嫌なので...
While関数で回数制限してみた。
【Program】
int i=0;
void setup() {
//initialize the digital pin as an output
//Pin 13 has on LED connected on most Arduino boords:
pinMode(
}
void loop(){
while (i < 5){
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
i++;
}
}