I want to send a char to active the dc motors car moving foward by bluethooth.
So I need to check whether the bluetooth is connected , it should print "Send any character to begin" and wait a char to be send if it is connected successfully.
then I push a button to send any char to the arduino to make the car moving forward ,like this :
void setup() {
Serial.begin(9600);
pinMode(InA1, OUTPUT);
pinMode(InB1, OUTPUT);
pinMode(PWM1, OUTPUT);
pinMode(InA2, OUTPUT);
pinMode(InB2, OUTPUT);
pinMode(PWM2, OUTPUT);
Serial.println("\nSend any character to begin : ");
while (Serial.available() && Serial.read()); // empty buffer
while (!Serial.available()); // wait for data
while (Serial.available() && Serial.read()); // empty buffer again
}
void loop() {
analogWrite(PWM1,100);
analogWrite(PWM2,100);
digitalWrite(InA1, LOW);
digitalWrite(InB1, HIGH);
digitalWrite(InA2, LOW);
digitalWrite(InB2, HIGH);}
The arduino can wait the char and active by sending a char ,but it doesn't show the string "\nSend any character to begin : ".