---
# System prepended metadata

title: 0424 Arduino 作業
tags: [Arduino]

---

---
title: 0424 Arduino 作業
tags: Arduino
---

### Arduino IDE 載點
[點擊下載](https://hackmd.io/@ntust-tech/0424_Arduino_hw)
---
### Team2
```
void setup() {
  // put your setup code here, to run once:
    pinMode(8,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
    for(int i=100;i>0;i--){
    digitalWrite(8,HIGH);
    delay(150-i);
    digitalWrite(8,LOW);
    delay(150-i);
    }
    for(int i=0;i<100;i++){
    digitalWrite(8,HIGH);
    delay(150-i);
    digitalWrite(8,LOW);
    delay(150-i);
    }
}
```
數位:滑鼠
類比:光、聲音、溫度

### Team 1
#### 類比 vs 數位
- 類比：聲音、底片
- 數位：開關、樓層

#### 挑戰題 1
```Arduino
//It's dirty
int LED_PIN = 8;

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

void loop() {
  int delayTime;
  for(delayTime = 200; delayTime >= 100; delayTime -= 10){
    digitalWrite(LED_PIN, HIGH);   
    delay(delayTime);                      
    digitalWrite(LED_PIN, LOW);   
    delay(delayTime);                       
  }
  for(delayTime = 100; delayTime <= 200; delayTime += 10){
    digitalWrite(LED_PIN, HIGH);  
    delay(delayTime);                   
    digitalWrite(LED_PIN, LOW);    
    delay(delayTime);                  
  }
}
```

#### 挑戰題2
```Arduino
```
---



### Team 3
```
void setup() {
  pinMode(8, OUTPUT);
}

void loop() {
  int delaytime;
  for(delaytime = 500 ; delaytime >= 100 ; delaytime-=100){
    digitalWrite(8, HIGH);
    delay(delaytime);
    digitalWrite(8, LOW);
    delay(delaytime);
  }
  for(delaytime = 100 ; delaytime <= 500 ; delaytime+=100){
    digitalWrite(8, HIGH);
    delay(delaytime);
    digitalWrite(8, LOW);
    delay(delaytime);
  }
}
```
數位(不連續)：節拍器
>抗雜訊很強

類比(連續)：心跳、聲音
>容易受雜訊干擾

```
void setup() {
  pinMode(2, INPUT);
  pinMode(4, INPUT);
  pinMode(8, OUTPUT);
}

void loop() {
  if(digitalRead(2) && digitalRead(4) == 1){
    digitalWrite(8, HIGH);
    delay(100);
    digitalWrite(8, LOW);
    delay(100);
  }
  else if(digitalRead(2) == 1 && digitalRead(4) == 0){
    digitalWrite(8, HIGH);
  }
  else if(digitalRead(4) == 1 && digitalRead(2) == 0){
    digitalWrite(8, HIGH);
    delay(1000);
    digitalWrite(8, LOW);
    delay(1000);
  }
  else{
    digitalWrite(8, LOW);
  }
}
```


