搜索代码

Lesson 57-6: Controlling Four LEDs with a Loop

Lesson 57-6: Controlling Four LEDs with a Loop

482-Lesson 57: Using Arrays and Loops with Arduino
语言: C++
++
int led[] ={2, 3, 4, 5};// Define LED pins in an array


void setup() {
  for(int i=0; i<4; i++)
  {
    pinMode(led[i], OUTPUT);// Define a pin as output   
  }
 

  
  Serial.begin(9600);// Initialize serial monitor

}

void loop() {
  for(int i=0; i<4; i++)
  {
      digitalWrite(led[i],LOW); // Turn all LEDs OFF
  }

  delay(1000);// Wait for 1 second

  for(int i=0; i<4; i++)
  {
    digitalWrite(led[i],HIGH); // Turn LED ON
    delay(1000);// Wait for 1 second
  }    
 
      

}

资源与参考

尚无可用资源。

文件📁

没有可用的文件。