Arduino实现C++方式打印输出

Arduino实现C++方式打印输出

📑实现基于C++方式那样打印输出信息,需要借助库来实现。

📝示例程序

#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字节。
  • 📝串口打印信息
    在这里插入图片描述
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值