我的 Arduino 上的蓝牙模块有问题,我正在尝试用手机应用程序中的按钮打开一扇门,但是当我按下应用程序中的按钮时,门不会移动。
#include <SoftwareSerial.h>
#include <Servo.h>
int mover;
int mover2;
Servo servoMotor1;
Servo servoMotor2;
char rxChar;
SoftwareSerial BTserial(10, 11);
void setup(){
Serial.begin(9600);
Serial.println("Bluetooth test program");
pinMode (4,INPUT);//Fin de carrera 1
pinMode (2,INPUT);//Fin de carrera 2
mover=90; //0 Abrir 180 Cerrar 60-120 Velocidades
mover2=150;//motor Cerradura
servoMotor1.attach(8);//Motor Pin8
servoMotor2.attach(9);//Motor Pin9
BTserial.begin(9600);
BTserial.println("Bluetooth test program");
}
void loop() {
int lectura;
int lectura2;
servoMotor1.write(mover);
servoMotor2.write(mover2);
lectura=digitalRead(4);//fin de carrera
lectura2=digitalRead(2);//fin de carrera
if (Serial.available())
{
BTserial.write(Serial.read());
}
if (BTserial.available())
{
Serial.write(BTserial.read());
char rxChar = BTserial.read();
}
if(rxChar=='a'){
Serial.print("60 Grados");
mover=60;
}
if(rxChar=='b'){
Serial.print("120 Grados");
mover=120;
}
if (lectura==LOW and mover==120){
mover=90;//motor frena
mover2=30;//Motor Cerradura Cerrado
}
if (lectura2==LOW and mover==60){
mover=90;//motor frena
}
}
当我按下按钮时,控制台返回“⸮”