如何在 Arduino 中獲得可用 RAM?
Arduino-MemoryFree 庫可用於獲取 Arduino 中的可用 RAM。要使用此庫,請先安裝。在 Arduino 中安裝第三方庫的說明在此提供:https://tutorialspoint.tw/using-a-third-party-library-in-arduino
安裝好後,轉到:檔案→示例→Arduino-MemoryFree。
例項
正如您所見,BareMinimum 示例名副其實。它真的很短。
#include <MemoryFree.h>;
#include <pgmStrToRAM.h>; // not needed for new way. but good to have for reference.
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
// forced to be compiled into and read
Serial.println(getPSTR("Old way to force String to Flash"));
// forced to be compiled into and read
Serial.println(F("New way to force String to Flash"));
//F function does the same and is now a built in library, in IDE > 1.0.0
Serial.println(F("Free RAM = "));
// print how much RAM is available.
Serial.println(freeMemory(), DEC);
// print how much RAM is available.
}
void loop() {
// put your main code here, to run repeatedly:
}主要功能是 freeMemory(),它以位元組為單位返回 Arduino 中的可用 RAM。如註釋所述,不再需要以下幾行。
#include <pgmStrToRAM.h>;
// forced to be compiled into and read
Serial.println(getPSTR("Old way to force String to Flash"));它們已被新增以顯示將字串儲存到快閃記憶體的舊方式與較新方式(使用 F() 宏)之間的差異。
廣告
資料結構
網路
關係型資料庫
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP