[英]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.