轉自: https://blog.csdn.net/y511374875/article/details/77845240
三種方式手動重啟Arduino
1.Arduino板上重新編寫代碼時,Arduino將重新設置 2.Arduino軟件中打開串行終端,同時將Arduino板連接到計算機。打開串行終端時,Arduino會自動重置 3.按下復位按鈕
兩種方式自動重啟Arduino
詳情見: https://www.theengineeringprojects.com/2015/10/upload-bootloader-atmega328.html
1.使用Arduino板上的RESET引腳以編程方式重新設置Arduino,就是利用一個數字口,代碼運行到那的時候就將REST置低 這里利用數字口D2
int Reset = 2;
void setup() { digitalWrite(Reset, HIGH); delay(200); pinMode(Reset, OUTPUT); Serial.begin(9600); Serial.println("How to Reset Arduino Programmatically"); delay(200); }
void loop() { Serial.println("A"); delay(1000); Serial.println("B"); delay(1000); Serial.println("Now we are Resetting Arduino Programmatically"); Serial.println(); delay(1000); digitalWrite(Reset, LOW); Serial.println("Arduino will never reach there.");
}1234567891011121314151617181920212223
2.不使用任何硬件引腳,Arduino有一個名為resetFunc()的內置函數,我們聲明函數地址為0,當我們執行此功能時,Arduino將自動重置。
說明: –In this method, we are not gonna use any hardware pin, instead we will do everything in programming. –Arduino has a builtin function named as resetFunc() which we need to declare at address 0 and when we execute this function Arduino gets reset automatically. –So, no need of doing anything in hardware and simply upload the below code in your Arduino board.
void(* resetFunc) (void) = 0;
void setup() { Serial.begin(9600); Serial.println("How to Reset Arduino Programmatically"); delay(200); }
void loop() { Serial.println("A"); delay(1000); Serial.println("B"); delay(1000); Serial.println("Now we are Resetting Arduino Programmatically"); Serial.println(); delay(1000); resetFunc(); Serial.println("Arrduino will never reach there.");
} --------------------- 作者:y511374875 來源:CSDN 原文:https://blog.csdn.net/y511374875/article/details/77845240 版權聲明:本文為博主原創文章,轉載請附上博文鏈接!