使用Arduino Software (IDE)內建範例開始練習
Built-in Examples are sketches included in the Arduino Software (IDE), to open them click on the toolbar menu: File > Examples.
These simple programs demonstrate all basic Arduino commands. They span from a Sketch Bare Minimum to Digital and Analog IO, to the use of Sensors and Displays.
1. Basics
Analog Read Serial: Read a potentiometer, print its state out to the Arduino Serial Monitor.
直接執行後啟動序列埠監控視窗,轉動可變電阻,觀察序列埠監控視窗的資料變化。
【練習】你可以讓序列埠監控視窗顯示光敏電阻的亮度變化值。
Bare Minimum: The bare minimum of code needed to start an Arduino sketch.
這是空白的程式架構
Blink: Turn an LED on and off.
直接執行可以看見主板右下角綠色LED閃爍。
【練習】修改輸出端子為D4,則右上角紅色LED閃爍。
【練習】修改輸出端子為D5,則蜂鳴器會震動,再縮短延遲時間聽聽看有何不同?
Digital Read Serial: Read a switch, print the state out to the Arduino Serial Monitor.
修改輸入端為D6直接執行可以觀察到按鈕開關狀態。
【練習】你可以改變按下時對應發光的LED嗎?
Read Analog Voltage: Reads an analog input and prints the voltage to the Serial Monitor.
直接執行後啟動序列埠監控視窗,轉動可變電阻,觀察序列埠監控視窗的資料變化。
【練習】你可以更改輸入端為A6,觀察光感知器的資料變化。
【練習】你可以更改輸入端為A2,用【工具】【序列繪圖家】觀察麥克風收音的波形變化。
Tone Melody: Play a melody with a Piezo speaker.
直接執行時電路喇叭毫無反應。
【練習】你可以改變程式讓喇叭發出聲音?
Arduino Software (IDE)新增元件程式庫
參考資料:
Arduino筆記:安裝 Arduino IDE 程式庫(Library)
Arduino 匯入的程式庫預設位置在 【(我的)文件】--> 【Arduino】--> 【libraries】底下,如果要刪除就直接進去刪掉就好。
安裝 OLED程式庫 U8g2
安裝 DHT11程式庫 simpleDHT
安裝 氣壓計程式庫 BMP280
安裝 三軸加速度計式庫 Grove-3-Axis-Digital-Accelerometer-2g-to-16g-LIS3DHTR