[arduino]-1-Basics代碼解讀
阿新 • • 發佈:2018-11-14
digi evel 永遠 level 工具 text pub model under
arduino IDE 自帶示例中的Basics系列,
可以說是
向一個擁有C系家族編程語言基礎的人
解釋清楚了它自己的基本操作
BareMinimum(基本文件結構):
void setup() { // put your setup code here, to run once: // 這裏放的setup代碼只會運行一次 } void loop() { // put your main code here, to run repeatedly: // 這裏放的主要代碼會在setup之後不停循環執行 }
Start(有修改):
// the setup routine runs once when you press reset://setup會在你按下reset之後首先執行 void setup() { // initialize the digital pin as an output. // 將數字端口初始化為輸出模式 pinMode(0, OUTPUT); //LED on Model B pinMode(1, OUTPUT); //LED on Model A or Pro } // the loop routine runs over and over again forever: //loop會一遍又一遍的永遠執行下去 void loop() { digitalWrite(0, HIGH); //turn the LED on (HIGH is the voltage level) // 打開LED(HIGH代表電壓高低) digitalWrite(1, HIGH); delay(1000); // wait for a second digitalWrite(0, LOW); // turn the LED off by making the voltage LOW // 將電壓降低來關閉LED digitalWrite(1, LOW); delay(1000); // wait for a second }
Blink:
/* Blink 閃爍 Turns an LED on for one second, then off for one second, repeatedly. 點亮LED持續1秒鐘,然後熄滅LED一秒鐘,一次循環。 Most Arduinos have an on-board LED you can control. 許多arduino都有一個板載LED可供使用 On the UNO, MEGA and ZERO it is attached to digital pin 13, on MKR1000 on pin 6. 在UNO,MEGA和ZERO上它與數字端口13相連。//後略 LED_BUILTIN is set to the correct LED pin independent of which board is used. LED_BUILTIN被設定為各種主板相對應的LED而與型號無關。 If you want to know what pin the on-board LED is connected to on your Arduino model, check the Technical Specs of your board at: 如果你想知道你的這種arduino上到底哪個端口連接著板載LED,那麽查看詳細的說明可以到: https://www.arduino.cc/en/Main/Products modified 8 May 2014 by Scott Fitzgerald modified 2 Sep 2016 by Arturo Guadalupi modified 8 Sep 2016 by Colby Newman This example code is in the public domain. http://www.arduino.cc/en/Tutorial/Blink */ // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin LED_BUILTIN as an output. // 將LED_BUILTIN端口初始化為輸出模式。 pinMode(LED_BUILTIN, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }
以上的代碼皆可直接下載到UNO上運行
關於具體代碼的理解,
請各位善用自己的英語知識
與互聯網工具
本節關鍵代碼詞匯含義對照:
setup ≈ set up 意思非常之多,初始化,安排,安裝,構建,都可以
loop 循環
pin 端口/針腳,1pin就是一根線,所以電腦裏面的電源插口,4P,6P,24P就是這樣來的
built in 內置/板載
digital 數字,關於模擬和數字的區別,你用著用著就明白了
delay 等待/延遲
[arduino]-1-Basics代碼解讀