Arduino示例代码讲解: For Loop Iteration 循环迭代

Arduino示例代码讲解: For Loop Iteration 循环迭代

  • For Loop Iteration 循环迭代
    • 功能概述
        • 硬件部分:
        • 软件部分:
      • 代码逐行解释
        • 定义变量
        • `setup()` 函数
        • `loop()` 函数
        • 第一个`for`循环:
        • 第二个`for`循环:
    • 工作原理

For Loop Iteration 循环迭代

这段代码是一个Arduino示例程序,用于演示如何使用for循环。它通过for循环依次点亮多个LED,然后按相反顺序熄灭它们。

/*
  For Loop Iteration

 Demonstrates the use of a for() loop.
 Lights multiple LEDs in sequence, then in reverse.

 The circuit:
 * LEDs from pins 2 through 7 to ground

 created 2006
 by David A. Mellis
 modified 30 Aug 2011
 by Tom Igoe

This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/ForLoop
 */

int timer = 100;           // The higher the number, the slower the timing.

void setup() {
   
  // use a for loop to initialize each pin as an output:
  for (int thisPin = 2; thisPin < 8; thisPin++) {
   
    pinMode(thisPin, OUTPUT);
  }
}

void loop() {
   
  // loop from the lowest pin to the highest:
  for (int thisPin =

你可能感兴趣的:(从零开始学习机器人,microsoft,嵌入式硬件,arduino,机器人,人工智能)