Arduino实现C++方式打印输出
Posted perseverance52
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Arduino实现C++方式打印输出相关的知识,希望对你有一定的参考价值。
Arduino实现C++方式打印输出
实现基于C++方式那样打印输出信息,需要借助库来实现。
-
所需包含的库:
Streaming.h
(在Arduino IDE库管理里面可以搜索到)
-
该库GitHub地址:https://github.com/janelia-arduino/Streaming
来个示例程序
#include <Streaming.h>
const long BAUD = 115200;
const int lettera = 'A';
const int month = 4, day = 17, year = 2009;
const int hour = 8, minute = 20, second = 3;
const long LOOP_DELAY = 1000;
void setup()
{
Serial.begin(BAUD);
}
void loop()
{
Serial << "This is an example of the new streaming" << endl;
Serial << "library. This allows you to print variables" << endl;
Serial << "and strings without having to type line after" << endl;
Serial << "line of Serial.print() calls. Examples: " << endl;
Serial << "A is " << lettera << "." << endl;
Serial << "The current date is " << day << "-" << month << "-" << year << "." << endl;
Serial << "You can use modifiers too, for example:" << endl;
Serial << _BYTE(lettera) << " is " << _HEX(lettera) << " in hex. " << endl;
Serial << endl;
Serial << "In library v6, you also get" << endl;
Serial << "Padding [" << _PAD(10, '*') << "]" << endl;
Serial << "Width specification [" << _WIDTH(10, 5) << "]" << endl;
Serial << "Leading zeros [" << _WIDTHZ(month,2) << "]" << endl;
Serial << _FMT("Format strings for stuff like dates and times %/%/% %:%:%",
_WIDTHZ(day, 2), _WIDTHZ(month, 2), year,
_WIDTHZ(hour,2), _WIDTHZ(minute, 2), _WIDTHZ(second,2)) << endl;
Serial << _FMT(F("To reduce your % size, these % can be in %"), F("sketch"), F("constants"), F("PROGMEM")) << endl;
Serial << endl;
delay(LOOP_DELAY);
}
- 编译信息
Executable segment sizes:
IROM : 234912 - code in flash (default or ICACHE_FLASH_ATTR)
IRAM : 26892 / 32768 - code in IRAM (ICACHE_RAM_ATTR, ISRs...)
DATA : 1248 ) - initialized variables (global, static) in RAM/HEAP
RODATA : 1100 ) / 81920 - constants (global, static) in RAM/HEAP
BSS : 24936 ) - zeroed variables (global, static) in RAM/HEAP
使用 6.0.9 版本的库 Streaming 在文件夹: C:\\Users\\Administrator\\Documents\\Arduino\\libraries\\Streaming
"C:\\\\Users\\\\Administrator\\\\AppData\\\\Local\\\\Arduino15\\\\packages\\\\esp8266\\\\tools\\\\xtensa-lx106-elf-gcc\\\\2.5.0-4-b40a506/bin/xtensa-lx106-elf-size" -A "d:\\\\arduino\\\\MyHexDir/StreamingExample.ino.elf"
项目使用了 264152 字节,占用了 (25%) 程序存储空间。最大为 1044464 字节。
全局变量使用了27284字节,(33%)的动态内存,余留54636字节局部变量。最大为81920字节。
- 串口打印信息
以上是关于Arduino实现C++方式打印输出的主要内容,如果未能解决你的问题,请参考以下文章
CH559L单片机基于Arduino框架下实现USB CDC虚拟串口打印ADC数据
Arduino 浮点数转字符数组输出,π常量输出,sprintf打印