如何在Arduino中将char变量作为数字打印到串行端口? [英] How to print in Arduino a char variable as a number to the Serial Port?
问题描述
我正在使用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屋!