2017年12月18日 星期一

在 Tinkercad 上使用Arduino模擬器(Arduino Simulator on TinkerCAD)

前言

Autodesk Circuits 已被移至 Tinkercad (https://www.tinkercad.com/circuits),除了原本的功能外,現在還可以使用Scratch積木來設計程式,實在是很方便。
Autodesk Circuits has moved to Tinkercad (https://www.tinkercad.com/circuits). Tinkercad Circuits has a additional function that enable Scratch-based programming to design a Arduino program. That's very easy and convenient for a beginner to learn C programming.

本文將簡短介紹兩個功能:
  1. Circuits 電路設計
  2. 積木程式設計
Two features are introduced in this tutorial:
  1. Circuits design
  2. Scratch-based programming

Circuits 電路設計(Circuits Design)

登入TinkerCAD後的畫面如下,請點選畫面左方的 Circuits 文字。
After logging in TinkerCAD, click the Circuits button on the left of the screen.


接著點選 Create new Circuit 文字,就會開啟電路設計畫面。
Then, click Create new Circuit button to open a new circuit project web page.


這裡就以讓LED閃爍為例子,先看個在下錄製的教學影片:
Here is a tutorial video for creating a LED blink.

注意 LED的短腳接在 UNO GND,LED長腳接在電阻後,再從電阻接至 UNO D13,完成的電路圖如下:
The finished circuits are the below picture. Please Note: a resistor(above 100 ohm) is needed for connected the LED and UNO.
有沒有注意到,我們不用程式設計,就可以控制 LED 燈的閃爍了。這是為什麼?
Here is a notice: the LED now is blinking without any programming. Why?

積木程式設計

說明程式積木之前,請先將原本接在 UNO D13 的線換到  UNO D2,接著在按下 Code Editor 按鈕(藍色箭頭所指)。
Before showing the Scratch-based programming, let's change the wire between the LED and the UNO board (rrom D13 to D2). Then, click the Code Editor(see the blue arrow on the below picture) to open Code Editor screen.

會在畫面下方出現程式設計的視窗,此視窗的左方為目前TinkerCAD Circuits所提供的積木程式,中間專案所設計的程式,右方為對應的Arduino C程式碼。
The Code Editor screen will appear on the bottom of the screen.

TinkerCAD預設會建立讓UNO板上頭有標示 L 文字的 LED 燈閃爍,而這個燈是與 UNO 的數位腳位 13 相連的。現在按下 Start Simulation 的按鈕時,會發現紅色 LED 燈不會閃爍了,那要怎麼做才能讓紅色 LED 燈閃爍呢?
TinkerCAD will create a Blink project for the built-in LED which are marked with a 'L' label. The built-in LED is connected with UNO digital pin 13. Now, the red LED doesn't blink when you click "Start Simulation" button. For blinking the red LED, what other things should be done?

請看底下的教學影片(Here are the tutorial video for coding):

完成的範例網址(The completed example):https://www.tinkercad.com/things/kTkVXA7385q

參考資料(Reference)
[1] Circuits Tutorials on Tinkercad: https://www.tinkercad.com/learn/