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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.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
Arduino 显示随机字符的串行监视器_Arduino_Bluetooth - Fatal编程技术网

Arduino 显示随机字符的串行监视器

Arduino 显示随机字符的串行监视器,arduino,bluetooth,Arduino,Bluetooth,我正试图建立一个L298n能够控制两个直流电机的速度(通过蓝牙),使用arduino UNO 我创建了一个MIT应用程序inventor应用程序,并尝试使用应用程序上的滑块功能来控制电机速度。但是,当我打开串行监视器,查看我连接到arduino上的RX和TX引脚以及5v和GND的HC05的输入时,出现了一些混乱。我附上了一张串行监视器产生的图像,我的MIT应用程序inventor阻止了它。我读到很多人通过波特率得到这个问题,但我的已经改为34800。 非常感谢您在解决此问题时提供的任何帮助。 代

我正试图建立一个L298n能够控制两个直流电机的速度(通过蓝牙),使用arduino UNO

我创建了一个MIT应用程序inventor应用程序,并尝试使用应用程序上的滑块功能来控制电机速度。但是,当我打开串行监视器,查看我连接到arduino上的RX和TX引脚以及5v和GND的HC05的输入时,出现了一些混乱。我附上了一张串行监视器产生的图像,我的MIT应用程序inventor阻止了它。我读到很多人通过波特率得到这个问题,但我的已经改为34800。 非常感谢您在解决此问题时提供的任何帮助。 代码如下:

int=6;
int-enB=3;
intin1=4;
int in2=9;
int-in3=8;
int-in4=2;
int val2;
无效设置(){
Serial.begin(38400);
pinMode(enA,输出);
pinMode(enB,输出);
pinMode(in1,输出);
pinMode(in2,输出);
引脚模式(in3,输出);
pinMode(in4,输出);
数字写入(in1,高);
数字写入(in2,低);
数字写入(in3,高);
数字写入(in4,低电平);
}
void循环(){
if(Serial.available()>=0){
unsigned int a=Serial.read();
unsigned int b=Serial.read();
无符号int val=(b*256)+a;
序列号println(val);

如果(val>=0&&val=1000&&val即使在没有字节可读取的情况下,也尝试读取串行缓冲区。请参阅if语句

if(Serial.available()>=0){
Serial.available()

只有当缓冲区中有内容时,才需要调用
Serial.read()
。将if语句更改为:

if(Serial.available()>0){
或者,简单地说

if(Serial.available()){