Arduino 入門學習筆記1 開發環境及雙色LED實驗
本系列學習教程來自 創樂博智慧學習視訊
Arduino 發展
2005年,Massimo Banzi和David Cuartielles、David Mellis設計 Arduino。取該名稱的原因是Massimo Banzi喜歡去一家名叫Arduino的酒吧,其名稱是1000年前義大利國王Arduino名字命名的。
Arduino 硬體分類
1. Arduino 開發板
開發板由一塊AVR微控制器、一個晶振和振盪器和一個5V的直流電源。常見的開發板通過一條USB資料線連線計算機。Arduino 有各式各樣的開發板,其中最通用的是Arduino UNO。 另外,還有很多小型的、微型的、基於藍芽和WiFi的變種開發板。
還有一款新增的開發板叫作Arduino Mega2560,提供了更多的I/O引腳和更大的儲存空間、啟動更迅速。
ArduinoUNO的處理器核心是ATmega328,同時具有14路數字輸入/輸出口(其中6路可作為PWM輸出),6路模擬輸入,一個16MHz的晶振振盪器,一個USB口、一個電源插座,一個ICSP header和一個復位按鈕。
Arduino UNO可以通過三 種方式供電,能自動選擇供電方式:外部直流電源通過電源插座供電;電池連線電源聯結器的GND和VIN引腳;USB介面供電。電源介面輸入的7-12V電源可通過開發板上5V穩壓器穩定到5V。
該穩壓器是AMST1117,三端5V穩壓器。該穩壓器輸入5V的時候會輸出3.3V,輸入9V的時候才輸出5V。如果使用5V 供電,接外設實驗會有些驅動不了。
A0~A5 : 模擬輸入的6個介面,可以用來測量連線到引腳上的電壓,測量值可以通過串列埠顯示出來。也可以作為數字訊號的輸入輸出。
Arduino 需要串列埠進行通訊,串列埠工作的時候串列埠指示燈會閃爍。Arduino通訊在編譯程式和下載程式時進行,同時還可以與其他裝置進行通訊。與其它裝置通訊時需要RX和TX引腳。Atmega328晶片中內建的串列埠通訊硬體是可以通過同步和非同步模式工作的。
——摘自《Arduino創客之路》
2. Arduino擴充套件硬體
3. UNO原理圖:
開發環境搭建
-
安裝 arduino-1.8.5-windows
-
檢查驅動:
-
設定arduino-windows埠:
-
上傳程式
-
麵包板接線
程式程式碼
/*************************************************** 湖南創樂博智慧科技有限公司 name:Dual-color LED function:you can see the dual-color LED changes from red to green alternately, as well as flashing a mixed color during the alternation. connection: Dual-color LED Arduin Uno R3 R 11 GND GND G 10 ****************************************************/ int redPin = 11; // select the pin for the red LED int greenPin = 10; // select the pin for the blueLED int val = 0; void setup() { pinMode(redPin, OUTPUT); //set redPin as OUTPUT pinMode(greenPin, OUTPUT);//set greenPin as OUTPUT Serial.begin(9600); } /******************************************************/ void loop() { for(val=255; val>0; val--) // { analogWrite(redPin, val); //red value decrease analogWrite(greenPin, 255-val);//green value increase Serial.println(val, DEC);//print the val on in serial monitor delay(30); //delay 30ms } for(val=0; val<255; val++) { analogWrite(redPin, val); //red value increase analogWrite(greenPin, 255-val);//green value decrease Serial.println(val, DEC);//print the val on in serial monitor delay(30); //delay 30ms } } /********************************************************/
執行效果