コンテンツへスキップ

Lesson 2: More LEDs

English

One pin for each LED

  • Each LED needs its own pin and its own pinMode.
  • In a real circuit each LED also needs a resistor (about 220 Ω), so it does not burn out.
void setup() {
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(12, HIGH);
  digitalWrite(13, LOW);
  delay(500);
  digitalWrite(12, LOW);
  digitalWrite(13, HIGH);
  delay(500);
}
  • Press Run: the two LEDs take turns.
  • The board is very fast. Two digitalWrite lines with no delay between them happen at (almost) the same time.

ログインまたはアカウント作成

IGCSE, A-Level & AP