Alright, I've been trying to figure this out. I've never really made a project like this with arduino before. I made a few smalls ones, but this one is complicated for me. I want to drive a motor and servo. I found some code I've been working off of to control the motor control module. I got the speed set the way I want it. The problem is when I try to implement the servo controls into the code. Once I do this..the motor goes in reverse. I know this is probably an easy fix for you arduino gurus but I'm still new..so give me a break ;D
// this uses the Arduino servo library included with version 0012
// caution, this code sweeps the motor up to maximum speed !
// make sure the motor is mounted securily before running.
#include <Servo.h>
Servo myservo;
Servo myservo2;
int pos = 0;
void arm(){
// arm the speed controller, modify as necessary for your ESC
setSpeed(0);
delay(1000); //delay 1 second, some speed controllers may need longer
}
void setSpeed(int speed){
// speed is from 0 to 100 where 0 is off and 100 is maximum speed
//the following maps speed values of 0-100 to angles from 0-180,
// some speed controllers may need different values, see the ESC instructions
int angle = map(speed, 0, 70, 0, 180);
myservo.write(angle);
}
void setup()
{
myservo.attach(8);
myservo.attach(9);
arm();
}
void loop()
{
int speed;
// sweep up from 0 to to maximum speed in 20 seconds
for(speed = 0; speed <= 90; speed += 5) {
setSpeed(speed);
delay(0);
}
setSpeed(100);
delay(500);
for(pos = 90; pos < 160; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo2.write(pos); // tell servo to go to position in variable 'pos'
delay(0); // waits 15ms for the servo to reach the position
}
}
Any help is appreciated, thanks.