前置作業
mbed 板子裡面其實有一個 .HTML 的檔案,當你點擊這個檔案後,會進入到 mbed 的登入畫面,若你有帳號的話,請在左邊輸入完資料後就可以登入到 mbed 的雲端編譯器,若沒有擇點選Sign up註冊,並將DISCO-L475VG-IOT01A設為你目前所使用的板子即可。
前置作業做完了,那這邊要來教各位第一個範例
1.LED交替閃爍
這邊的話,首先,在這個頁面點擊左方的My Programs右鍵創建新檔,點擊之後於第二欄Template選擇最下面的Empty Program即可創建。

在中間的框框右鍵New File即可(記得,檔案名後要.cpp)。
創建完後,先點擊左上角的Import,在左上角的搜尋,輸入mbed並點擊兩下第一個,即可安裝。
之後,我們回到前面的.cpp文件。
輸入以下程式碼:

注意:我們前面有#include,所以需要額外import程式庫,點選右上方的import,後在右邊的搜尋欄中輸入mbed,點擊框中黑框兩下即可安裝。

並點擊上方的Compile,待其跑完進度條,將新增的.bin檔案放入mbed板子即可。
2.A/D讀取 光敏電阻讀值
這邊的話,首先,在這個頁面點擊左方的My Programs右鍵創建新檔,點擊之後於第二欄Template選擇最下面的Empty Program即可創建。

在中間的框框右鍵New File即可(記得,檔案名後要.cpp)。
創建完後,先點擊左上角的Import,在左上角的搜尋,輸入mbed並點擊兩下第一個,即可安裝。
之後,我們回到前面的.cpp文件。
輸入以下程式碼:

注意:我們前面有#include,所以需要額外import程式庫,點選右上方的import,後在右邊的搜尋欄中輸入mbed,點擊框中黑框兩下即可安裝。

並點擊上方的Compile,待其跑完進度條,將新增的.bin檔案放入mbed板子,然後打開arduino的序列埠即可觀看數據。
以下是接線圖:

小知識:

線路中,R2 愈大,V=IR原理,V是常數5V,R愈大I就愈小(保護Arduino),但是,A2量到的電壓就愈高(壓降一點點)。
所以,若是要A2讀出的值高,R2就要愈大,可是,A2讀出的變化也不大(不靈敏)。
若要A2讀值靈敏一點(數值變動大),R2就要小一點,這樣壓降會在A2位置就會先發生。
以下為實測數據:

