Hi,
I'm making a sorting hat that when button push, the servo will moving and sending the message to app.
My problem is i pushing the button but app will receive the message after a very long time, or even don't get it! (I'm sure about my bluetooth connection, servo will moving, and app can receive another message)
Can anyone tell me what happen to my code? thanks.
Here is my code:
#include <Servo.h>
#include<SoftwareSerial.h>
SoftwareSerial I2CBT(10,11); //Bluetooth:hc-06
Servo myservo1;
Servo myservo2;
int btn=0;
const int TX=10;
const int Rx=11;
byte serial_code;
void setup()
{
Serial.begin(9600);
I2CBT.begin(57600);
pinMode(13,INPUT);
}
void loop()
{
btn=digitalRead(13);
if (btn == HIGH) {
//star the servo
myservo1.attach(3, 500, 2400);
myservo2.attach(5, 500, 2400);
//sending the messege to phone(!problem here!)
I2CBT.write(3);
Serial.println("yes");
//-----------------------------------------
//伺服馬達轉動控制
for(int i = 1200; i <= 1500; i+=15){
myservo2.writeMicroseconds(i);
delay(50);
}
for(int i = 1000; i <= 1500; i+=15){
myservo1.writeMicroseconds(i);
delay(50);
}
for(int i = 1500; i >= 1000; i-=15){
myservo1.writeMicroseconds(i);
delay(50);
}
for(int i = 1500; i >= 1200; i-=15){
myservo2.writeMicroseconds(i);
delay(50);
}
}
else
{
Serial.println("no");
//sending the messege to phone(this can work!)
I2CBT.write(2);
}
}
and my app: