Bluetooth help

I think that explains it.

void forward(char a,char b)

/* Is this where you are actually declaring a and b. Are they declared this way because earlier they were called by forward (leftspeed,rightspeed); /*

analogWrite (E1,a); //same as saying (E1,leftspeed)
digitalWrite(M1,LOW);
analogWrite (E2,b); //same as saying (E2,rightspeed)
digitalWrite(M2,LOW);

OMG I’ve jacked this thread up.:astonished:

Thank you for looking into the hardware portion of it. So let me post the code and see if I am following your logic.

case ‘w’://Move Forward - This is calling the forward function
forward (leftspeed,rightspeed); //I understand leftspeed,rightspeed was defined earlier with 255 which is max speed
break;//how could I have robot only move while holding w

void forward(char a,char b)/because the function called was forward(leftspeed,rightspeed), here is where a and b are declared/
{
Serial.println (“Moving Forward”);
analogWrite (E1,a);//this is the same as saying (E1,leftspeed
digitalWrite(M1,LOW);
analogWrite (E2,b);//this is the same as saying (E2,rightspeed)
digitalWrite(M2,LOW);
}

So looking at my comments, hopefully I’ve nailed it. When writing the algorithm for the forward function, because it was called earlier with forward(leftspeed,rightspeed), when definig this it know char a is leftspeed and char b is right speed. Am I correct?

Also another thing I was wondering is in the comments. How would I set it to only move while holding w instead of moving until another key is pressed?

Welcome the forums!

For your first question, we will need to look into this in more detail: it’s pretty odd that you have to do this.

For your second question, ‘a’ and ‘b’ are passed in as parameters when the ‘forward’ function is called. By default, we provide ‘leftspeed’ and ‘rightspeed’ as the two parameters, and they are both set to 255, the maximum speed.

The reason we have two parameters is to allow adjustments to the left or right speed to compensate for any manufacturing/assembly inconsistencies that make one of the rover tracks move faster than the other. If you observe this, reduce the value of the faster track from 255 to something slower like 245. It’s a trial and error process to find the exact value that will allow your rover to drive straight.

We hope this helps for Q2, and we will need to get back to you for Q1.

Yes, you understood properly.

To be able to make the robot move only when keys are held, you would first need to make a program for your computer that has a little more features than the Arduino Serial Monitor: the program would have to check the status of the keys, or have events observing their changes, and then send the appropriate commands to the robot.

You can make your program so that when a key is pressed, the program sends that key to the rover, and then when a key is released, the program sends another key, such as space, to the rover which will make it stop. This wouldn’t actually require any changes to the rover code.

The reason you can’t do this with the Arduino Serial Monitor is because it works differently: when a key is pressed, it adds that key to the list of characters to be send to the rover, and the list itself is only sent when the Send button or the Enter key is pressed. This unfortunately does not work well for your preferred design.

We hope this helps,