Successfully reported this slideshow.
Upcoming SlideShare
×

# Arduino: Analog I/O

2,838 views

Published on

Published in: Education
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

### Arduino: Analog I/O

1. 1. 阿爾杜伊諾 Arduino: Lv. 2Mutienliao.TW 智慧生活與創新設計, 2013-03-25
2. 2. ArduinoIntroduction
3. 3. Analog Out Analog Out 類比輸出
4. 4. Analog Output Arduino 的PWM pin只有3,5,6,9,10,11 PWM (Pulse Width Modulation) 電腦與微處理器是不可能實際輸出類比的電壓(僅能0~5V)。 但我們可以假造出類似的效果。 若快速在兩個電壓中做切換，我們可以得到⼀一個平均值： Output Voltage = High_time(%) * Max_Voltage
5. 5. Arduino 的PWM pin只有3,5,6,9,10,11類比輸出0~5V對應的數值為0~255analogWrite( pin, val )
6. 6. #4 | Fade 實作呼吸燈的效果
7. 7. #4的練習程式，在 File > Examples > Basic > Fadeint brightness = 0; // how bright the LED isint fadeAmount = 5; // how many points to fade the LED byvoid 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);}
10. 10. 輸入才是互動的精華
12. 12. Potentiometer
13. 13. Photocell get value get value get value
14. 14. Arduino 的類比輸入使用A0~A5類比輸入0~5V對應的數值為0~1023analogRead( pin )
15. 15. #10 | analog_control
16. 16. #10的練習程式，在 http://mutienliao.tw/arduino/analog_control.pdeint ledPin = 13; // LED connected to digital pin 13int analogPin = 0; // photocell connected to analog pin 0int val = 0;void setup(){ pinMode(ledPin, OUTPUT); // sets the digital pin as output}void loop(){ val = analogRead(analogPin); // read the value from the sensor if(val<80) { digitalWrite(ledPin, HIGH); // sets the LED on } else { digitalWrite(ledPin, LOW); // sets the LED off } delay(50);}
17. 17. 修改#10的練習程式，取得analogRead進來的數值int ledPin = 13; // LED connected to digital pin 13int analogPin = 0; // photocell connected to analog pin 0int val = 0;void setup(){ pinMode(ledPin, OUTPUT); // sets the digital pin as output Serial.begin(9600);}void loop(){ val = analogRead(analogPin); // read the value from the sensor Serial.println(val); if(val<80) { digitalWrite(ledPin, HIGH); // sets the LED on } else { digitalWrite(ledPin, LOW); // sets the LED off } delay(50);}
18. 18. 我們可以先用Arduino Software提供的Serial Monitor來先測試Arduino板子端傳來的訊息。 你要傳的訊息輸入 傳送來的訊息 546756456575456745674567447 baud rate 設定