Hi,
I'm trying to drive a brushless motor via an ESC which worked fine, now I am trying to have it read data from serial and control the motor with the serial data but I'm having a problem.
After it inits it sits there idle, then after sending a value to the com port it goes to the speed for the duration of Delay() but then no more.
The code is messy (I haven't done a whole lot with the Arduino) as it's got bits and pieces from different projects/posts
// 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>
int serspeed = 0;
Servo myservo;
void arm(){
// arm the speed controller, modify as necessary for your ESC
setSpeed(30);
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, 100, 0, 180);
myservo.write(angle);
}
void setup()
{
myservo.attach(12);
arm();
Serial.begin(9600);
pinMode(serspeed, OUTPUT);
}
void loop()
{
serspeed = Serial.read();
setSpeed(serspeed);
delay(1000);
}