# Arduino最基本的代碼
> 這個例子包含了讓Arduino IDE?**編譯**通過所需要的最基本代碼:**setup()**?函數和**loop()**函數。
### 所需硬件
* Arduino板或Genuino板
* 面包板線/杜邦線
### 電路
本例僅僅需要一塊Arduino板或Genuino板?

### 代碼
setup()函數在工程啟動時被調用。你可用它來初始化變量、定義引腳工作模式、初始化**代碼庫**(library)等等。setup函數在板子每次通電或**重新初始化**(reset)后僅被調用一次。
在創建setup()函數之后,loop()函數就會開始“工作”了。恰如其名(loop意為循環),它會不斷的被執行。使用loop函數你就可以真正地在運行時“掌控”你的這塊Arduino板了。工程內loop()函數的代碼被用作在運行時控制這塊板。
下列代碼并不會做實質性的工作,但它的結構可供你在任何將來想做的項目上套用。本例也向你展示了如何在代碼中進行**代碼注釋**。
每個以 “//”開頭的代碼行都不會被**編譯器**讀取,因此你可在”//”的后面寫任何你想要的東西。當然, “//”也可能會被放在代碼行的末尾。像下面這樣書寫代碼注釋將會使代碼容易理解,并使讀者能夠一步一步地了解軟件運行過程。
~~~
void setup() {
// 這里請寫初始化代碼,本函數只運行一次。
}
void loop() {
// 將主要的代碼放在這里以重復執行。
}
~~~
## 相關資料
[setup()](http://www.arduino.cc/en/Reference/Setup)?
[loop()](http://www.arduino.cc/en/Reference/Loop)?
[讀取模擬信號、串口操作?
讀取數字引腳?
點亮LED?
LED亮度漸隱?
讀取模擬電壓]( )
- 說明
- 系統示例文件目錄結構及說明
- 01.Basics
- AnalogReadSerial
- BareMinimum
- Blink
- DigitalReadSerial
- Fade
- ReadAnalogVoltage
- 02.Digital
- BlinkWithoutDelay
- Button
- Debounce
- DigitalInputPullup
- StateChangeDetection
- toneKeyboard
- toneMelody
- toneMultiple
- tonePitchFollower
- 03.Analog
- AnalogInOutSerial
- AnalogInput
- AnalogWriteMega
- Calibration
- Fading
- Smoothing
- 04.Communication
- ASCIITable
- Dimmer
- Graph
- Midi
- MultiSerial
- PhysicalPixel
- ReadASCIIString
- SerialCallResponse
- SerialCallResponseASCII
- SerialEvent
- SerialPassthrough
- VirtualColorMixer
- 05.Control
- Arrays
- ForLoopIteration
- IfStatementConditional
- switchCase
- switchCase2
- WhileStatementConditional
- 06.Sensors
- ADXL3xx
- Knock
- Memsic2125
- Ping
- 07.Display
- barGraph
- RowColumnScanning
- 08.Strings
- CharacterAnalysis
- StringAdditionOperator
- StringAppendOperator
- StringCaseChanges
- StringCharacters
- StringComparisonOperators
- StringConstructors
- StringIndexOf
- StringLength
- StringLengthTrim
- StringReplace
- StringStartsWithEndsWith
- StringSubstring
- StringToInt
- 09.USB
- Keyboard
- KeyboardLogout
- KeyboardMessage
- KeyboardReprogram
- KeyboardSerial
- KeyboardAndMouseControl
- Mouse
- ButtonMouseControl
- JoystickMouseControl
- 10.StarterKit_BasicKit (與特定硬件相關,暫無)
- p02_SpaceshipInterface
- p03_LoveOMeter
- p04_ColorMixingLamp
- p05_ServoMoodIndicator
- p06_LightTheremin
- p07_Keyboard
- p08_DigitalHourglass
- p09_MotorizedPinwheel
- p10_Zoetrope
- p11_CrystalBall
- p12_KnockLock
- p13_TouchSensorLamp
- p14_TweakTheArduinoLogo
- p15_HackingButtons
- 11.ArduinoISP(暫無)
- ArduinoISP