LoginSignup
0
0

More than 3 years have passed since last update.

arduino UNOの基板上のLEDでLED点滅(Lチカ)

Last updated at Posted at 2020-05-23

この記事は、2020-05-23に書いて、2020-05-24に更新しました。


概略

Arduino UNO には、基板上にLEDが実装されています。このLEDを点滅させて、いわゆるLチカをやってみます。
本体以外に何もいらないので、Arduino UNO の動作確認にぴったりです。

環境・部品

PC:Windows 10 Professional
開発環境:Arduino IDE 1.8.12
本体:Arduino UNO Rev3

コード

BuiltinLEDBlink.ino
void setup() {
    pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
    digitalWrite(LED_BUILTIN, HIGH);
    delay(500);
    digitalWrite(LED_BUILTIN, LOW);
    delay(500);
}

解説

基本的に、ファイル>>スケッチ例>>01.Basics>>Blink と同じです。まったく同じだと芸がないので、点滅の間隔を短くしています。
ピン番号を指定するときにLED_BUILTINと指定していますが、これは基板上のLED番号を表すマクロで、pins_arduino.hの中で、

pins_arduino.h
#define LED_BUILTIN 13

と定義されています。基板上のLEDは、13番ピンに繋がっているということです。

参考

pinMode()(公式、英語)
digitalWrite()(公式、英語)
delay()(公式、英語)

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0