Upload
cavedu-education
View
765
Download
5
Embed Size (px)
Citation preview
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
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
電路示意圖
Fritzinghttp://fritzing.org/
Fritzing
元件內容
元件庫繪圖區
123D circuits
• 由AutoDesk公司推出的線上電路模擬軟體