如何在Arduino中将char变量作为数字打印到串行端口? [英] How to print in Arduino a char variable as a number to the Serial Port?

查看:588
本文介绍了如何在Arduino中将char变量作为数字打印到串行端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Arduino Uno.我正在从EEPROM读取一个字节值,并将该值存储在char类型(1个字节)的变量中.

I am using Arduino Uno. I am reading a byte value from the EEPROM and storing the value in a variable of type char (1 byte).

我想将变量的值打印为数字(而不是打印到相应的ASCII码)到串行监视器.例如,考虑char val = 5. 我想查看串行监视器5而不是ASCII值.

I want to print the value of the variable as a number (not to the corresponding ASCII code) to the Serial Monitor. For example consider char val = 5. I want to see to the Serial Monitor 5 and not the ASCII value.

我同时尝试了Serial.print(val)Serial.write(val),但结果是相同的:它始终打印ASCII码.

I tried both Serial.print(val) and Serial.write(val) but the result is the same: it prints always the ASCII code.

如何将值打印到串行监视器?

How can I print the value to the Serial Monitor?

谢谢.

推荐答案

char变量转换为unsigned char类型:

Serial.print( (uint8_t) c );

这调用了不同的print方法.它们超载".

This calls a different print method. They are "overloaded".

这篇关于如何在Arduino中将char变量作为数字打印到串行端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆