---
# System prepended metadata

title: arduino 填空用
tags: [code]

---

---
title: arduino 填空用
tags: code
---

### LED control_1
```c++
int ledpin = '填入腳位';

void setup()
{
  pinMode(ledpin, OUTPUT);
}

void loop()
{
  digitalWrite(ledpin, HIGH);
}
```

### LED control_2
```c++
int ledpin = '填入腳位';

void setup()
{
  pinMode(ledpin, OUTPUT);
}

void loop()
{
  digitalWrite(ledpin, HIGH);
  delay(1000); 
  digitalWrite(ledpin, LOW);
  delay(1000);
}
```
### LED control_3
```c++
int Gpin = '填入腳位';
int Ypin = '填入腳位';
int Rpin = '填入腳位';

void setup()
{
  pinMode(Gpin , OUTPUT);
  pinMode(Ypin , OUTPUT);
  pinMode(Rpin , OUTPUT);
}

void loop()
{
  digitalWrite(Gpin , HIGH);
  digitalWrite(Ypin , HIGH);
  digitalWrite(Rpin , HIGH);
  delay(1000);
  digitalWrite(Gpin , LOW);
  digitalWrite(Ypin , LOW);
  digitalWrite(Rpin , LOW);
  delay(1000);
}
```

### LED control_4
```c++
int Gpin = '填入腳位';
int Ypin = '填入腳位';
int Rpin = '填入腳位';
int counter;

void setup()
{
  pinMode(Gpin , OUTPUT);
  pinMode(Ypin , OUTPUT);
  pinMode(Rpin , OUTPUT);
}

void loop()
{
  // 紅燈亮
  digitalWrite(Gpin , LOW);
  digitalWrite(Ypin , LOW);
  digitalWrite(Rpin , HIGH);
  delay(3000);
  
  // 黃燈閃
  digitalWrite(Gpin , LOW);
  digitalWrite(Ypin , HIGH);
  digitalWrite(Rpin , LOW);

  for (counter = 0; counter < 3; ++counter) {
    digitalWrite(Ypin, LOW);
    delay(500); 
    digitalWrite(Ypin, HIGH);
    delay(500); 
  }

  // 綠燈亮
  digitalWrite(Gpin , HIGH);
  digitalWrite(Ypin , LOW);
  digitalWrite(Rpin , LOW);
  delay(3000);
}
```

### LED control_5
```c++
int ledpin = 3 ;
int buttonpin = 7 ;

void setup()
{
  pinMode(buttonpin, INPUT);
  pinMode(ledpin, OUTPUT);
}

void loop()
{
  if (digitalRead(buttonpin) == 0) {
    digitalWrite(ledpin, HIGH);
  } else {
    digitalWrite(ledpin, LOW);
  }
}
```