---
# System prepended metadata

title: 604 20 洪俊翔

---

蜂鳴器
![](https://hackmd.io/_uploads/rJ_09L5-a.png)

```javascript=
void setup()
{
  pinMode( 6 , OUTPUT);
}

void loop()
{
  digitalWrite(6 , HIGH);
  tone(5, 440);
  delay( 1000 );
  tone(6, 600);
  delay( 1000 );
  noTone(6);
}
```


超音波感應器
https://hackmd.io/_uploads/rJDLasAJT.png


```javascript=
t ardublockUltrasonicSensorCodeAutoGeneratedReturnCM(int trigPin, int echoPin)
{
  long duration;
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(20);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  duration = duration / 59;
  if ((duration < 2) || (duration > 300)) return false;
  return duration;
}



void setup()
{
  Serial.begin(9600);
  digitalWrite( 3 , LOW );

}

void loop()
{
  Serial.print("message");
  Serial.print(	ardublockUltrasonicSensorCodeAutoGeneratedReturnCM( 3 , 4 ));
  Serial.print(" ");
  Serial.println();
  delay( 1000 );
}
```
PIR紅外線人體感測

![](https://hackmd.io/_uploads/B14SzdBJ6.png)
```javascript=
void setup()
{
  pinMode( 4 , OUTPUT);
}

void loop()
{
  digitalWrite(4 , HIGH);
  delay( 500 );
  digitalWrite(4 , LOW);
  delay( 500 );
}
```

LED
![](https://hackmd.io/_uploads/B14KP1_gp.png)
```javascript=
boolean __ardublockDigitalRead(int pinNumber)
{
  pinMode(pinNumber, INPUT);
  return digitalRead(pinNumber);
}



void setup()
{
  Serial.begin(9600);
}

void loop()
{
  Serial.print(__ardublockDigitalRead(2));
  Serial.print(" ");
  Serial.println();
  delay( 1000 );
}
```