如何使用程式方式重置(reset) Arduino [Arduino software reset ~ How to reset Arduino by programming?]

如何使用程式方式重置(reset) Arduino [Arduino software reset ~ How to reset Arduino by programming?]

如何使用程式方式重置(reset) Arduino [Arduino software reset ~ How to reset Arduino by programming?]


資料來源:https://www.instructables.com/two-ways-to-reset-arduino-in-software/

https://arduinogetstarted.com/faq/how-to-reset-arduino-by-programming


Declare (宣告/定義)

void(* resetFunc) (void) = 0;  // declare reset fuction at address 0


Call (呼叫/執行)

resetFunc(); //call reset


Ex: (實際範例)

int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
  Serial.begin(9600);//initialize the serial port
}
void(* resetFunc) (void) = 0; //declare reset function @ address 0


// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  Serial.println("on");
  delay(1000);               // wait for a second

  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  Serial.println("off");
  delay(1000);               // wait for a second
  Serial.println("resetting");
  resetFunc();  //call reset
  
  delay(100);
  Serial.println("never happens");
}

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *