[英]Arduino doesn't turn off vibration after inputting 0
I have arduino UNO with bluetooth module and vibration motor attached. 我有连接蓝牙模块和振动马达的arduino UNO。 I can turn on the vibrator but cant seem to turn it off.
我可以打开振动器,但似乎无法关闭它。 Here's the code
这是代码
#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:
}
In the bluetooth terminal, it stated <1> Vibrator on when i input '1' but also stated <0) Vibrator on when i input '0' when it should've been Vibrator off. 在蓝牙端子中,当我输入“ 1”时,它表示<1>振动器打开,但当我应将“ Vibrator”关闭时,当其输入“ 0”时,它也声明<0)振动器打开。
Appreciate all the help 感谢所有帮助
if(BluetoothData='1'){
^
Single =
is assignment. 单个
=
是分配。 Use ==
for comparisons. 使用
==
进行比较。
Also, BluetoothData
should probably be defined as a local variable in loop()
. 同样,应该将
BluetoothData
定义为loop()
的局部变量。 It'll work either way, but will compile to slightly more efficient (and more readable!) code. 无论哪种方式,它都可以工作,但是会编译为稍微更有效(和更易读!)的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.