如何在 Arduino 中获得可用 RAM?
Arduino-MemoryFree 库可用于获取 Arduino 中的可用 RAM。要使用此库,请先安装。在 Arduino 中安装第三方库的说明在此提供:https://tutorialspoint.com/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