Hi guys !
I'm completely new to this forum and Arduino, so first of all, nice to meet all of you and thank you for taking time to read my problems.
So here is the thing, I'm making this project where I'm trying to control 5 haptic vibration motors with my phone. There will be several patterns of vibration according to which buttons I press on the app.
Right now I'm trying to check the different patterns with the serial monitor but things absolutely not happen the way I want.
I'm using an Arduino Nano V.3 compatible (not an official one), a HC-05 bluetooth module and 5 vibration motors. (I added in the attachments pictures of my wiring).
Here is my code below, what I would like to happen is that when I press "a" or "b" the script which is in the function gets followed.
But when I press "a" the script does 'a' function + 3 times 'b' function, and when I press "b" it does 2 times 'b' function.
This is very annoying, especially because I don't know wether my wiring is wrong of if my code is wrong, in any case I'm a beginner at both.
Thanks for reading and helping !
Lucas
char data = 0;
const int haptic5 = 5;
const int haptic4 = 3;
const int haptic2 = 9;
const int haptic1 = 11;
const int haptic3 = 6;
void setup()
{
Serial.begin(9600);
}
void loop()
{
if(Serial.available() > 0)
{
data = Serial.read();
Serial.print(data);
//Serial.print("\n");
if(data == 'a')
{
analogWrite(haptic1, 100);
analogWrite(haptic2, 100);
analogWrite(haptic3, 100);
analogWrite(haptic4, 100);
analogWrite(haptic5, 100);
delay(500);
analogWrite(haptic1, 0);
analogWrite(haptic2, 0);
analogWrite(haptic3, 0);
analogWrite(haptic4, 0);
analogWrite(haptic5, 0);
}
else if(data == 'b');
{
analogWrite(haptic1, 255);
delay(500);
analogWrite(haptic1, 0);
delay(500);
analogWrite(haptic1, 255);
delay(400);
analogWrite(haptic1, 0);
delay(400);
analogWrite(haptic1, 255);
delay(300);
analogWrite(haptic1, 0);
delay(300);
analogWrite(haptic1, 255);
delay(200);
analogWrite(haptic1, 0);
delay(200);
}
}
}