Hey, I'm writing this code, to connect the Arduino Mega to an applcation i've made on MIT app inventor. Basically when i press a button on my tablet, it activates the vibrator on the mega. When i first started my project i was using an Uno, and this code worked fine, but since i've changed to the mega nothing is happening. Can someone please help me to fix this!!
int Bouton;
int vibreur = 8;
etatBouton = 0;
int recvChar;
#include <SoftwareSerial.h> //Software Serial Port
#define RxD 6
#define TxD 7
#define DEBUG_ENABLED 1
SoftwareSerial blueToothSerial(RxD, TxD);
word w; //mot qui recoit les trames emises par la tablette
void setup() {
Serial.begin(9600);
pinMode(vibreur, OUTPUT);
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
setupBlueToothConnection();
}
void loop() {
recevoir();
while (1) {
if (blueToothSerial.available()) { //check if there's anydata sent from the remote bluetooth shield
recvChar = blueToothSerial.read();
Serial.print(recvChar);
if (recvChar == 118) {
digitalWrite(vibreur, HIGH);
delay(500);
digitalWrite(vibreur, LOW);
delay(200);
digitalWrite(vibreur, HIGH);
delay(500);
digitalWrite(vibreur, LOW);
delay(1500);
}
}
}
}
void setupBlueToothConnection()
{
blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400
blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
delay(2000); // This delay is required.
blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
Serial.println("The slave bluetooth is inquirable!");
delay(2000); // This delay is required.
blueToothSerial.flush();
}
void recevoir() {
if (blueToothSerial.available()) {
w = blueToothSerial.read();
blueToothSerial.flush();
}
}