flush()
描述
刪除所有未讀的簡訊內容。
flush()
是從 Stream
繼承而來。
語法
SMS.flush()
參數
無參數
回傳
無回傳值
範例
/* SMS receiver 監控是否有收到簡訊,收到簡訊時把簡訊內容輸出到序列埠監控視窗 Circuit: * GSM shield created 25 Feb 2012 by Javier Zorzano / TD This example is in the public domain. */ // 函式庫 #include <GSM.h> // PIN 碼 #define PINNUMBER "" // 初始化 GSM 函式庫 GSM gsmAccess; // include a 'true' parameter for debug enabled GSM_SMS sms; // 用來存放電話號碼的字元陣列 char remoteNumber[20]; void setup() { // 初始化 Serial Serial.begin(9600); Serial.println("SMS Messages Receiver"); // 連線狀態 boolean notConnected = true; // 啟動 Arduino GSM shield,如果你的 SIM 卡有 PIN 碼,請當作 begin() 的參數 while(notConnected) { if(gsmAccess.begin(PINNUMBER)==GSM_READY) notConnected = false; else { Serial.println("Not connected"); delay(1000); } } Serial.println("GSM initialized"); Serial.println("Waiting for messages"); } void loop() { char c; // 檢查是否有未讀的簡訊 if (sms.available()) { Serial.println("Message received from:"); // 取得傳送簡訊的電話號碼 sms.remoteNumber(remoteNumber, 20); Serial.println(remoteNumber); // 這是一個刪除簡訊的範例,在這裡把開頭為 # 的簡訊刪除 if(sms.peek()=='#') { Serial.println("Discarded SMS"); sms.flush(); } // 讀取簡訊內容並輸出到序列埠監控視窗 while(c=sms.read()) Serial.print(c); Serial.println("\nEND OF MESSAGE"); // 刪除簡訊 sms.flush(); Serial.println("MESSAGE DELETED"); } delay(1000); }
See also
- GSM_SMS
- beginSMS()
- ready()
- endSMS()
- available()
- remoteNumber()
- read()
- write()
- print()
- peek()
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.