繁体   English   中英

输入0后Arduino无法关闭振动

[英]Arduino doesn't turn off vibration after inputting 0

我有连接蓝牙模块和振动马达的arduino UNO。 我可以打开振动器,但似乎无法关闭它。 这是代码

#include<SoftwareSerial.h>//import the serial library

int vib=8;
SoftwareSerial Genotronex(10,11);//RX,TX
int BluetoothData;//the data given

void setup() {
Genotronex.begin(9600);
Genotronex.println("Bluetooth on please press 1 to vibrate");
pinMode(vib,OUTPUT);
// put your setup code here, to run once:
}

void loop() {
if (Genotronex.available()){
BluetoothData=Genotronex.read();{
if(BluetoothData='1'){
  digitalWrite(vib,'1');
  Genotronex.println("Vibrator on");
  delay(500);

  }
  else if (BluetoothData='0'){
  digitalWrite(vib,'0');
  Genotronex.println("Vibrator off");
  delay(500);

  }   
  }
  }
delay(100);
// put your main code here, to run repeatedly:
}

在蓝牙端子中,当我输入“ 1”时,它表示<1>振动器打开,但当我应将“ Vibrator”关闭时,当其输入“ 0”时,它也声明<0)振动器打开。

感谢所有帮助

if(BluetoothData='1'){
                ^

单个=是分配。 使用==进行比较。

同样,应该将BluetoothData定义为loop()的局部变量。 无论哪种方式,它都可以工作,但是会编译为稍微更有效(和更易读!)的代码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM