#include //共用變數放這裡 int D=1000,ND=0; int mode=0,flag=0; int addr =30; unsigned long T,T1; void setup() { //設定區,一開始執行一次 pinMode(13, OUTPUT);// Serial.begin(115200); D = EEPROM.read(addr); Serial.println(D); T=0;T1=0; } void loop() { //主要程式區,此區會不斷的重複執行 if (millis()-T>D){ if (flag==0){ digitalWrite(13, HIGH); flag=1; } else { digitalWrite(13, LOW); flag=0; } T=millis(); } } void serialEvent() { while (Serial.available()) { char inc = (char)Serial.read();//將byte轉成 char if (mode==0 && inc=='S') { mode=1; ND=0; } if (mode==1 && inc=='E'){ D=ND; mode=0; ND=0; EEPROM.write(addr, D); Serial.print("now D="); Serial.println(D); } if (inc=='R') { Serial.print("EEEPROM="); Serial.println(EEPROM.read(addr)); } if (mode==1 &&(inc>='0'&& inc<='9')){ ND=ND*10+(inc-'0'); } } }