在c++中通过串行发送一个带符号的整数作为字节,Arduino读取它
Send a signed integer as a byte via serial in c++ and Arduino read it
我可以通过串行发送字符串,但Arduino读取字符串的速度非常慢。因此,我在Arduino中使用读取字节,但问题是我不知道如何在C++中通过串行端口将数字(<256)作为字节发送。
如果打开Arduino IDE,在菜单下,查看:
File > Examples > 08.Strings > CharacterAnalysis
在这里,我想你会发现一些非常接近你想要的东西。总之,它打开一个串行连接(USB)并读取计算机的输入。(你需要确保你匹配波特率并使用"发送"按钮。)这取决于你是否按照自己的意愿对Arduino进行编程。在示例的情况下,它只是将反馈发送回串行监视器。自己运行它,看看会发生什么:)
示例中的[MCVE]片段:
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
// send an intro:
Serial.println("send any byte and I'll tell you everything I can about it");
Serial.println();
}
void loop() {
// get any incoming bytes:
if (Serial.available() > 0) {
int thisChar = Serial.read();
// say what was sent:
Serial.print("You sent me: '");
Serial.write(thisChar);
}
相关文章:
- 检查TCHAR数组输入是否为带符号整数C++
- GDB:运行不带符号的 cpp 进程调试
- 使用范围检查和带符号的size_type扩展std::vector
- 将fortran生成的二进制文件读取到C++中的带符号整数数组中
- 用于在2个带符号整数区间之间进行除法的C++算法
- 如何从uint8_t的缓冲区读取带符号整数,而不调用未定义或实现定义的行为
- 是否删除整数的符号扩展
- 仅使用位操作(不使用分支)将16位带符号值约束在0和4095之间
- 如何在C++中附加一个整数(带一个整数)
- 在c++中通过串行发送一个带符号的整数作为字节,Arduino读取它
- 带符号的16位SSE平均值
- types.h中的内容——编译器在哪里定义int、带符号int和其他值的宽度
- 使用带符号字符输入的isalnum-Visual C++
- 如何对具有带符号数字类型的事物进行谓词
- mkdir,带符号的路径名
- 返回特定位范围内的带符号值
- 为什么唯一的带符号整数类型会导致clang中的溢出警告
- 使用reinterpret_cast强制转换导致:OverflowError:带符号整数小于最小值
- 格式化带符号十六进制数字的输出
- 如何在C++中安全地比较32位整数和64位整数,以及如何在内部比较带符号整数