Arduino 習作計畫 #1 燈光
提供優質服務 Total Solution Provider
http://www.cavedu.com
http://blog.cavedu.com
Arduino Introduction • Massimo Banzi 和 David Cuartielles所設計 • 採用低價位微處理器 ,Atmel Atmega8/168/328 單晶片 • 開放式的軟硬體平台
Arduino UNO USB Port 外接電源(DC) Digital(PWM ) 通訊 Power燈 Reset 類比輸入電壓 in/out
Install the Arduino Driver http://www.arduino.cc/
Install the Arduino Driver
Getting Started • 指定Arduino Driver資料夾位置
Getting Started • 打開裝置管理員,將”連接埠”展開,確認USB Serial Port
Getting Started • 將Arduino.exe打開,在tools下選擇正確的Board與Serial Port
LED Blink • File >> Examples >> 1.Basics >> Blink
LED Blink • Verify & Upload Verify Upload Status
How does it work? void setup() {  初始化 } void loop() {  重複執行 ...}
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 }
動手寫寫看!
基本範例 (File >> Example >> Basic >> Fade)
程式 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); }
可變電阻
讀取類比腳位狀態 (File >> Example >> Basic>> AnalogReadSerial) void setup() { Serial.begin(9600); } void loop() { int sensorValue = analogRead(A 0); Serial.println(sensorValue); delay(1); }
接線 • 中間:A0~A5 • 一側:5V • 另一側:GND
可變電阻控制LED漸明漸暗 (File >> Example >> Analog >> AnalogInOutSerial)
光敏電阻 • 一端接A0,一端接地 • 由於是被動元件,需要在A0 那端加上5V
電路示意圖
Fritzing http://fritzing.org/
Fritzing 元件內容 元件庫 繪圖區
123D circuits • 由AutoDesk公司推出的線上電路模擬軟體

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

Editor's Notes

  • #7 1.據說 Massimo Banzi 之前是義大利 Ivrea 一家高科技設計學校的老師。他的學生們經常抱怨找不到便宜好用的微控制器。2005年冬天, Massimo Banzi 跟David Cuartielles 討論了這個問題。David Cuartielles 是一個西班牙籍晶片工程師,當時在這所學校做訪問學者。兩人決定設計自己的電路板 2.使用低價格的微處理控制器(ATMEGA8/168/328) NT$120~NT$150 3.Arduino是一塊基於開放原始碼的Simple i/o介面版,並且具有使用 類似java,C語言的開發環境 Arduino可以使用開發完成的電子元件例如Switch或sensors或其他 控制器、LED、步進馬達或其他輸出裝置。當然我們現在也可以拿來控制樂高。
  • #8 請學員把板子拿下來 1. USB port 2. POWER light 3.外接dc 4.電壓inout 5. 類比輸入 6. digital(pwm) (communicate) 7. restt