So i've been trying to make this table tennis robot that shoots balls automatically which i can control through an app in my smart phone. This is a school project of mine which is due 1 week from now. I ran into a bit of a problem with controlling the two motors for my launcher. Here's the section of the code that i'm having trouble with:
if (val >= 2000 && val < 2255)
{
int ballMapped = val;
ballMapped = map(ballMapped, 2000, 2255, 0, 255);
if (spinType == "topspin") {
motorSpeed1 = 255;
motorSpeed2 = 0;
motorSpeed2 = motorSpeed2 + ballMapped;
if (motorSpeed2 > 120 ) {
motorSpeed2 = 120;
}
}
if (spinType == "underspin") {
motorSpeed2 = 255;
motorSpeed1 = 0;
motorSpeed1 = motorSpeed1 + ballMapped;
if (motorSpeed1 > 120) {
motorSpeed1 = 120;
}
}
What this does is it takes the variable "val" which is from my smartphone app, it is a slider with values ranging from 2000 - 2255. Then I mapped those values to 0 - 255 which i put into ballMapped. There's also a checkbox in my smartphone that sends the word "topspin" or "underspin". Now if for example i checked topspin on the smartphone app, motor1 would spin at full speed because of motorspeed1 = 255 while motorspeed2 will be controlled by the slider. Now here's the problem whenever i check underspin, motor2 will now spin at full speed but now motor1 can't be controlled by the slider, it won't even turn on. Does anyone know how to solve this or at least have another idea on how to control these two motors? Help would be very much appreciated.
UPDATE:
I found the culprit. Servo.attach was actually interfering with the motors, I did a little research and turns out that you can't use pin 9,10 for pwm if you're using the servo library. After that, I just rewired enA,in1,and in2 to pins 11,12,and 13, and thank God, it worked. Thank you so much for everyone who helped, I really appreciate it.