Hello I am working on a bar which is controlled by Arduino Leonardo using Bluetooth communication. I have bluetooth terminal app in my smartphone were I can create various buttons. I have 3 buttons and each of them starts process of making a certain drink. When I push Button 1 in terminal, it sends "1" through bluetooth to Arduino, when I push Button 2 it sends "2" etc. The problem is when I push the button multiple times. It will do the cycle, make drink and then when it is finished it will start all over again, pumps start pumping again according to buttons I pushed and the liquids will overleak from the glass... So I ask if there is any way to stop Arduino from reading information I send or clear the bluetooth buffer or something ? Thanks in advance for your replies.
code:
#include <SoftwareSerial.h> // library for serial communication
SoftwareSerial BT(10, 11); // 10 - RX, 11 - TX
int BluetoothData; // variable for BluetoothData
const int motorPin1 = 2; // Pump 1.
const int motorPin2 = 3; // Pump 2.
const int motorPin3 = 4; // Pump 3.
//------------------ SETUP -----------------------------------------------------------------------
void setup() {
Serial.begin(9600);
BT.begin(9600);
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(piezo, OUTPUT);
}
//-----------------LOOP---------------------------------------------------------------------------
void loop() {
if (BT.available()){
BluetoothData=BT.read();
//--------------------DRINK 1---------------------------------------------------------------------
if(BluetoothData=='1'){ // If received data from Bluetooth are '1' start making the drink number 1
Serial.println("Making drink 1.");
delay(1000);
digitalWrite(motorPin1, HIGH);
delay(2000);
digitalWrite(motorPin1, LOW);
delay(1000);
digitalWrite(motorPin2, HIGH);
delay(2000);
digitalWrite(motorPin2, LOW);
delay(1000);
digitalWrite(motorPin3, HIGH);
delay(2000);
digitalWrite(motorPin3, LOW);
delay(1000);
Serial.println("Drink 1 is done");
}
//--------------------DRINK 2---------------------------------------------------------------------
if (BluetoothData=='2'){ // If received data from Bluetooth are '2' start making the drink number 2
Serial.println("Making drink number 2.");
delay(1000);
digitalWrite(motorPin3, HIGH);
delay(2000);
digitalWrite(motorPin3, LOW);
delay(1000);
digitalWrite(motorPin2, HIGH);
delay(2000);
digitalWrite(motorPin2, LOW);
delay(1000);
digitalWrite(motorPin1, HIGH);
delay(2000);
digitalWrite(motorPin1, LOW);
delay(1000);
Serial.println("Drink 2. done");
}
//--------------------DRINK 3---------------------------------------------------------------------
if(BluetoothData=='3'){ // If received data from Bluetooth are '3' start making the drink number 3
Serial.println("Making drink number 3.");
delay(1000);
digitalWrite(motorPin2, HIGH);
delay(2000);
digitalWrite(motorPin2, LOW);
delay(1000);
digitalWrite(motorPin1, HIGH);
delay(2000);
digitalWrite(motorPin1, LOW);
delay(1000);
digitalWrite(motorPin3, HIGH);
delay(2000);
digitalWrite(motorPin3, LOW);
delay(1000);
Serial.println("Drink 3. done");
}
}
}