Arduino 習作工坊 - Lesson 1 燈光之夜

29
Arduino 習作計畫 #1 燈光

Transcript of Arduino 習作工坊 - Lesson 1 燈光之夜

Page 1: Arduino 習作工坊 - Lesson 1 燈光之夜

Arduino 習作計畫

#1 燈光

Page 2: Arduino 習作工坊 - Lesson 1 燈光之夜

提供優質服務

Total Solution Provider

Page 3: Arduino 習作工坊 - Lesson 1 燈光之夜
Page 4: Arduino 習作工坊 - Lesson 1 燈光之夜

http://www.cavedu.com

Page 5: Arduino 習作工坊 - Lesson 1 燈光之夜

http://blog.cavedu.com

Page 6: Arduino 習作工坊 - Lesson 1 燈光之夜

Arduino Introduction

• Massimo Banzi 和 David Cuartielles所設計

• 採用低價位微處理器,Atmel Atmega8/168/328 單晶片

• 開放式的軟硬體平台

Page 7: Arduino 習作工坊 - Lesson 1 燈光之夜

Arduino UNO

USB Port

外接電源(DC)

Digital(PWM )通訊

Power燈

Reset

類比輸入電壓 in/out

Page 8: Arduino 習作工坊 - Lesson 1 燈光之夜

Install the Arduino Driver

http://www.arduino.cc/

Page 9: Arduino 習作工坊 - Lesson 1 燈光之夜

Install the Arduino Driver

Page 10: Arduino 習作工坊 - Lesson 1 燈光之夜

Getting Started

• 指定Arduino Driver資料夾位置

Page 11: Arduino 習作工坊 - Lesson 1 燈光之夜

Getting Started

• 打開裝置管理員,將”連接埠”展開,確認USB Serial Port

Page 12: Arduino 習作工坊 - Lesson 1 燈光之夜

Getting Started• 將Arduino.exe打開,在tools下選擇正確的Board與Serial

Port

Page 13: Arduino 習作工坊 - Lesson 1 燈光之夜

LED Blink

• File >> Examples >> 1.Basics >> Blink

Page 14: Arduino 習作工坊 - Lesson 1 燈光之夜

LED Blink

• Verify & Upload

Verify

Upload

Status

Page 15: Arduino 習作工坊 - Lesson 1 燈光之夜

How does it work?

void setup() { 初始化

}

void loop() { 重複執行

...}

Page 16: Arduino 習作工坊 - Lesson 1 燈光之夜

How does it work?

int led = 13;

void setup() { // initialize the digital pin as an output. // Pin 13 has an LED connected on most Arduino boards:

pinMode(13, OUTPUT); }

void loop() {digitalWrite(led, HIGH); // set the LED on delay(1000);

// wait for a second digitalWrite(led, LOW); // set the LED off delay(1000); // wait for a second}

Page 17: Arduino 習作工坊 - Lesson 1 燈光之夜

動手寫寫看!

Page 18: Arduino 習作工坊 - Lesson 1 燈光之夜

基本範例(File >> Example >> Basic >> Fade)

Page 19: Arduino 習作工坊 - Lesson 1 燈光之夜

程式

int brightness = 0; // how bright the LED is

int fadeAmount = 5; // how many points to fade the

LED by

void setup() { // declare pin 9 to be an output:

pinMode(9, OUTPUT);

}

void loop() { // set the brightness of pin 9:

analogWrite(9, brightness); // change the

brightness for next time through the loop:

brightness = brightness + fadeAmount; // reverse

the direction of the fading at the ends of the fade:

if (brightness == 0 || brightness == 255){

fadeAmount = -fadeAmount ;

} // wait for 30 milliseconds to see the dimming

effect

delay(30);

}

Page 20: Arduino 習作工坊 - Lesson 1 燈光之夜

可變電阻

Page 21: Arduino 習作工坊 - Lesson 1 燈光之夜

讀取類比腳位狀態(File >> Example >> Basic>> AnalogReadSerial)

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

}

void loop() {int sensorValue = analogRead(A

0);Serial.println(sensorValue);

delay(1);

}

Page 22: Arduino 習作工坊 - Lesson 1 燈光之夜

接線

• 中間:A0~A5

• 一側:5V

• 另一側:GND

Page 23: Arduino 習作工坊 - Lesson 1 燈光之夜

可變電阻控制LED漸明漸暗(File >> Example >> Analog >> AnalogInOutSerial)

Page 24: Arduino 習作工坊 - Lesson 1 燈光之夜

光敏電阻

• 一端接A0,一端接地

• 由於是被動元件,需要在A0 那端加上5V

Page 25: Arduino 習作工坊 - Lesson 1 燈光之夜

電路示意圖

Page 26: Arduino 習作工坊 - Lesson 1 燈光之夜

Fritzinghttp://fritzing.org/

Page 27: Arduino 習作工坊 - Lesson 1 燈光之夜
Page 28: Arduino 習作工坊 - Lesson 1 燈光之夜

Fritzing

元件內容

元件庫繪圖區

Page 29: Arduino 習作工坊 - Lesson 1 燈光之夜

123D circuits

• 由AutoDesk公司推出的線上電路模擬軟體