is anyone familiar with this?
This is the Follow Me Cooler code. I am running a pair of motors that I don't know the full specs on but were part of a 6V tracked toy. I am using a 12V battery pack to power them as I already own it and may be using other 12V devices on board later on. I don't want to add a 3rd power supply.
The plan was to use PWM to only run the motors at ~ 50% to keep from burning them out. Looking at the provided code I can not figure out where or how the speed is determined. He has made comments like this but how does that set it to 200?:
void setSpeedMotorA(int speed) {
digitalWrite(MOTOR_A_IN_1_PIN, LOW);
digitalWrite(MOTOR_A_IN_2_PIN, HIGH);
// set speed to 200 out of possible range 0~255
analogWrite(MOTOR_A_EN_PIN, speed + MOTOR_A_OFFSET);
}
void setSpeedMotorB(int speed) {
digitalWrite(MOTOR_B_IN_1_PIN, LOW);
digitalWrite(MOTOR_B_IN_2_PIN, HIGH);
// set speed to 200 out of possible range 0~255
analogWrite(MOTOR_B_EN_PIN, speed + MOTOR_B_OFFSET);
}
void setSpeed(int speed)
{
// this function will run the motors in both directions at a fixed speed
// turn on motor A
setSpeedMotorA(speed);
// turn on motor B
setSpeedMotorB(speed);
}
But I don't see where speed is actually declared. "speed" is not in the .h either except for setting an offset to match motors.
Thank you, but that wasn't the question.
Where is the value coming from? How does that make "200"? If you read my question, how do I set the speed closer to 50%?
Later on "fullspeed and autothrottle are given values of 230. Is that it? how does that relate to the "speed" variable? I don't understand how speed is set or how I can change it.
Functions setSpeedMotorA() and setSpeedMotorB() are called from somewhere. When they called are the value in brackets (speedA or speedB) is put into their internal variable speed.
The code as provided calls setSpeedMotorA and setSpeedMotorB in the function drive(), which is itself called from driveTo(), which I think is tied into the Blynk framework.
See my confusion? Thanks for that. I'm still a bit out from using this so I have time. I still need to get the GPS and digital compass. Can't really test before that. When I have those I'll hook up a pair of larger motors I have for another project and play with it without fearing burning them out. I just wanted to try to understand the code before loading it finding problems. I know others have used it so it works. Maybe I'll swap project platforms so it isn't an issue.
Anyway, thanks again.
The best way to proceed with a complex program is to get each bit working separately, and understand it completely, before moving on. Then put the pieces together.
In this case, start with the simplest possible example that can command the motor to run in a certain direction and at a certain speed.
Google "Arduino motor control" for millions of possibilities and adapt one or more to suit your hardware.
I have several sketches I've written for motor control. I don't know if this can be broken down into parts. Everything is interdependent. On-board GPs, Android GPS, bluetooth, compass... Must all be working before anything will move. I'll keep hacking at it and I'll eventually figure it out. I just hoped someone on here had actually tried it.
Thanks for the reply.