講解運動科學的理論,及垂直跳躍檢測器所使用的硬件後,就開始著手編程。 Arduino 官方編程,支援 C/C++ 等,即一般程式語言,現時也支援 Block-based programming 類型的 Scratch 進行編程,讓非技術類型的學生也能駕馭。
如果要為 Arduino 編程,除了使用官方網站提供的 Arduino IDE ,還可以使用 mBlock ,這個程式是以 Scratch 為基礎的拖拉式方塊開發環境,不像在 Arduino IDE 中,不需輸入文字進行編程,讓初學者或學生更加容易學習編寫程式,開發 Arduino 的習作。現時 mBlock 可以支援得到大部分 Arduino 各類型號的開發版,例如 Uno 、 Leonardo 及 Nano 等。
預備 mBlock 程式編寫
編寫程式的方法很簡單,只需要在相關的模組中,選取你需要的方塊,並拖到 mBlock 環境中,便可以將程式建立好。然後切換至 Arduino Mode ,就可以進入文字式編程介面,最後為 Ardunio 連線,並按下 Upload to Arduino ,就可以將程式上載至 Arduino 開發板中,非常方便。
Arduino IDE: https://www.arduino.cc/en/Main/Software
mBlock: https://www.mblock.cc/software/mblock
[row][double_paragraph]

[/double_paragraph][double_paragraph]

[/double_paragraph] [/row]
mBlock 編程
接著就是用 mBlock 編程,首先用 USB 線將 Arduino Uno 開發板與電腦接駁著,然後開啟 mBlock 軟件程式,在畫面中預設了一隻熊貓角色 M-Panda ,接著會在熊貓裡編寫程式。
[row][double_paragraph]

擋著畫面就可以。
[/double_paragraph][double_paragraph]

讓程式與硬件連接。
[/double_paragraph] [/row]
[row][third_paragraph]

[/third_paragraph][third_paragraph]

[/third_paragraph][third_paragraph]

[/third_paragraph][/row]
方塊程式中,分別由 Scratch (綠色旗)和 Arduino Program 部分組成, Scratch 部分負責處理由 Arduino 及其他感應器中拿取的數據訊號,並可以將過程中的運算及結果展示在電腦的屏幕上。另外 Arduino Program 部分是負責驅動或設定 Arduino 不同接口為高位( High )或低位( Low ),在習作中需要用上兩個部分,就是完整的程式。