Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bluetooth 从Arduino Mega上的蓝牙读取字符串_Bluetooth_Arduino - Fatal编程技术网

Bluetooth 从Arduino Mega上的蓝牙读取字符串

Bluetooth 从Arduino Mega上的蓝牙读取字符串,bluetooth,arduino,Bluetooth,Arduino,我正在尝试使用蓝牙模块HC-05读取arduino mega上的字符串。模连接到端口18和19(串行1) 这是我写的函数。它应该接收5588-#并在收到字符时剪切传入消息,但我得到的输出是随机剪切的字符串(58,588,8-,-,等等) 我在这里做错了什么?经过大量的时间测试,我意识到如果我设置了延迟(1000)在循环中,而循环中的代码将正确运行 这不是最好的解决方案,但很有效。我不是有意的。我不知道它在那里,它与我正在做的事无关 static String getCommand() {

我正在尝试使用蓝牙模块HC-05读取arduino mega上的字符串。模连接到端口18和19(串行1)

这是我写的函数。它应该接收
5588-#
并在收到
字符时剪切传入消息,但我得到的输出是随机剪切的字符串(
58
588
8-
-
,等等)


我在这里做错了什么?

经过大量的时间测试,我意识到如果我设置了
延迟(1000)
循环中,而
循环中的代码将正确运行


这不是最好的解决方案,但很有效。

我不是有意的。我不知道它在那里,它与我正在做的事无关
    static String getCommand() {
        // Serial1.listen();
        char character = 0;
        String command = "";

        while (Serial1.available() > 0) {
            character = Serial1.read();
            if (character != '#') {
                character = character & 0x7F;
                command += character;
            } else {
                // Serial.println("return");
                return command;
            }
        }
    }